REST = REpresentational State Transfer (web standard architecture)

– uses HTTP Protocol
– every component is a resource (Text Files, Html Pages, Images, Videos or Dynamic Business Data,…)
– resource is accessed by a common interface using HTTP standard methods
– resource in REST is a similar Object in Object Oriented Programming or is like an Entity in a Database
– REST Server simply provides access to resources and REST client accesses and modifies the resources
– each resource is identified by URIs/ global IDs
– various representation to represent a resource (text, JSON, XML,…)

RESTful web service components

– URI (Uniform Resource Identifier a service)
– resource representation such as JSON
– set of HTTP Methods

What makes something RESTful?

Not any HTTP-based interface is a REST API, but RPC (Remote Procedural Call). If the engine of application state (and hence the API) is not being driven by hypertext, then it cannot be RESTful and cannot be a REST API. The side effect of NOT including hypermedia in our representations is that clients MUST hard code URIs to navigate the API.

HTTP Methods
Method Description
GET read only access to a resource
PUT update an existing resource, create a new resource
POST create a new resource
DELETE remove a resource
Response status codes
Code Description Example use
1XX Information communicates transfer protocol-level information
2XX Success indicates that the client’s request was accepted successfully
3XX Redirection indicates that the client must take some additional action in order to complete their request
4XX Client Error this category of error status codes points the finger at clients
5XX Server Error the server takes responsibility for these error status codes

Client -> HTTP Request -> HTTP -> HTTP Response -> Server

HTTP Request components:
– URI − identify the resource on the server

– HTTP Version − HTTP version (HTTP v1.1.,…)
– Request Header − metadata as key-value pairs (e.g. client (or browser) type, format supported by the client, format of the message body, cache settings,…)
– Request Body − message content, resource representation

HTTP Response components:
– Status/Response Code − e.g. 404 means resource not found, 200 means response is ok,…
– HTTP Version
– Response Header
– Response Body

Spring boot annotations
Annotation Description Example use
@ SpringBootApplication Convenience annotation that adds: @Configuration, @EnableAutoConfiguration, @EnableWebMvc and @ComponentScan @SpringBootApplication public class Application {…
@Configuration Tags the class as a source of bean definitions for the application context
@EnableAutoConfiguration Tells Spring Boot to start adding beans based on classpath settings, other beans, and various property settings
@EnableWebMvc This flags the application as a web application and activates key behaviors such as setting up a DispatcherServlet
@ComponentScan Tells Spring to look for other components, configurations, and services in the hello package, allowing it to find the controllers.
@Controller xxx xxx
@ResponseBody xxx xxx
@RestController Marks the class as a controller where every method returns a domain object instead of a view. It’s shorthand for @Controller and @ResponseBody rolled together. @RestController public class SomeController
@RequestMapping Ensures that HTTP requests to /methodName are mapped to the methodName() method @RequestMapping(“/methodName”)
@RequestMapping(method=GET) By default, @RequestMapping maps all HTTP operations. To narrow it down use method=XXX. @RequestMapping(method=GET, “/methodName”)
@RequestParam Binds the value of the query string parameter into the parameter of the methodName() method. If parameter is absent, defaultValue is used. methodName(@RequestParam(value=”name”, defaultValue=”UserName”)
@GetMapping xxx @GetMapping(“/someName”)
@GetMapping xxx @PostMapping(“/someName”)
@xxx xxx xxx