August 24, 2019 Vignesh Sathiyanantham

When I was writing the base code in Spring boot for my RESTifying the ZFS APIs project, I was looking for some way of throwing the exception to the user with HTTP error code. I found a way to handle it by using ResponseStatusExceptionResolver. ResponseStatusExceptionResolver is introduced with Spring 3, and Its main responsibility is to use the @ResponseStatus annotation available on custom exceptions and to map these exceptions to HTTP status codes. @ResponseStatus annotation I created a ValidationException class extending the RuntimeException class with a constructor. This is how my code looks like package in.asvignesh.zfsservice.controller; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus;…

August 24, 2019 Vignesh Sathiyanantham

I am working on a new hobby project RESTifying the ZFS APIs, Earlier I was using play framework for my REST projects, now started using SpringBoot While RESTifying the ZFS API one of the API formats is like @GetMapping(path = {“/”, “/{poolname}”, “/{poolname}/{volumename}”}, produces = “application/json”) / will give all the pool name and volumes, /poolname will give all the pool name and volumes of that particular pool, /poolname/”poolname/volumename” should give the pool and the volume. The volume name is in the format {poolname}/{volumename}, so I want to provide the slash with URL encoded but given restful method below gives…

August 13, 2019 Vignesh Sathiyanantham

In this post will see how to secure the REST API using Basic Authentication with Spring security features. In this example, we will be using Spring boot to avoid basic configuration I will describe only the security part of Spring REST and how to test with Postman Basic Authentication in REST API Basic authentification is a standard HTTP header with the user and password encoded in base64 : Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==.The userName and password are encoded in the format username: password. This is one of the simplest technique to protect the REST resources because it does not require cookies. session…

August 8, 2019 Vignesh Sathiyanantham

I have created my own annotation with default values set overriding the existing defaults In request parameters @RequestParam you can set the required parameters, I am implementing the Get Users and Get User by Name APIs Legacy way of implementing @RequestMapping(value = “/user/{name}”) public String getUsers(@PathVariable String name) { return service.getUsers(name); } @RequestMapping(value = “/user”) public String getUsers() { return service.getUsers(); } Instead of duplicating the APIs and overloading the method we can use the Java 8 Optional Parameter @RequestMapping(value = {“/”, “/{username}”}, verb = RequestMethod.GET) public ResponseEntity<List<User>> getUsers( @PathVariable(value = “username”, required = false) Optional<String> username) { if (username.isPresent())…

April 10, 2018 Vignesh Sathiyanantham

To fetch the querystring parameters in Controller we usually use request().queryString() Map<String, String[]> queryString = request().queryString(); If we have multiple query-string keys and want to use a POJO to use query-string instead of parsing everything in Controller we can use QueryStringBindable If you have take a look in your project you will see just simple parameters as argument ( Path argument ) in your GET method controller, In order to use Java POJO as input for query string i implements QueryStringBindable<T> in my POJO Here is my sample POJO and my controller method https://gist.github.com/asvignesh/911ff1b6dd4b96a5368e9d113a6591d0 Added a entry in routes, GET…

January 28, 2018 Vignesh Sathiyanantham

Cloud computing came through long way by replacing layer after a layer we used bare metal server then Virtual servers then Containers now Serverless computing Serverless is the next evolution of application and system design and deployment. Serverless applications are built upon functions—small code artifacts, which are compact and specific to a disc Serverless doesn’t mean servers are no more required to run workloads, it simply means that developers no longer have to think about them, this will make the developers focus more on tasks than servers. Serverless is often called as Function as service Amazon AWS has FaaS called…

January 28, 2018 Vignesh Sathiyanantham 29Comment

AWS Lambda lets you run code without provisioning or managing servers. You pay only for the compute time you consume – there is no charge when your code is not running. With Lambda, you can run code for virtually any type of application or backend service – all with zero administration. Just upload your code and Lambda takes care of everything required to run and scale your code with high availability. You can set up your code to automatically trigger from other AWS services or call it directly from any web or mobile app. In my last post, i wrote…

January 15, 2018 Vignesh Sathiyanantham

Today’s developers and organizations are migrating large, monolithic legacy applications to microservice-based architectures to improve scalability and developer velocity. However, these benefits come at a cost, namely integration complexity. Additionally, developers still often interact directly with the infrastructure, whether it be virtual machines (VMs) or containers via Kubernetes or another container orchestrator. Serverless is the next evolution of application and system design and deployment. Serverless applications are built upon functions—small code artifacts, which are compact and specific to a discrete task. Serverless doesnt means servers are no more required to run workloads, it simply means that developers no longer has…

January 8, 2015 Vignesh Sathiyanantham

HTTP GET The HTTP GET method is used to retrieve (or read) a representation of a web resource. In the non-error ( aka Happy path ) path, GET returns a representation in form of XML or JSON and the HTTP Status code will be 200 (OK). In case of any error in the path, it most often returns a 404 (NOT FOUND) or 400 (BAD REQUEST). According to the design of the HTTP specification, GET requests are used only to read data and not change it. Therefore, when used this way, they are considered safe. That is, they can be…

January 8, 2015 Vignesh Sathiyanantham 1Comment

Representational State Transfer (REST) has gained widespread acceptance across the Web as a simpler alternative to other Web services ( SOAP and WSDL ). REST is an architecture style or design pattern used as a set of guidelines for creating web services which allow anything connected to a network to communicate with one another via a shared common communications protocol known as Hypertext Transfer Protocol (HTTP). The same HTTP verbs (GET, POST, PUT, DELETE etc.) used by web browsers to retrieve and display web pages, audio/video files, images etc. from remote servers and post data back to them when performing…