RESTful Web Service





# HTTP Request and Response

Once a web service is created, front-end will be able to communicate with the service by sending a HTTP request which contains information needed for specific operation to be performed by the web service. HTTP methods are used to specify how the information will be passed in the HTTP reqeust and which operation needs to be performed by the web service.


Server side needs to know what type of contents a HTTP request carries in its body (XML or JSON...), so that they can convert it to Java object, and vice versa. HTTP headers include these information.

HTTP headers
- Content-Type : in request
- Accept : in response






# RESTful Web Service (API)

Representational State Transfer (REST) is an architectural style

* Advantages
  • Client-Server: This constraint operates on the concept that the client and the server should be separate from each other and allowed to evolve individually.
  • Stateless: REST APIs are stateless, meaning that calls can be made independently of one another, and each call contains all of the data necessary to complete itself successfully.
  • Cache: Because a stateless API can increase request overhead by handling large loads of incoming and outbound calls, a REST API should be designed to encourage the storage of cacheable data.
  • Uniform Interface: The key to the decoupling client from server is having a uniform interface that allows independent evolution of the application without having the application’s services, or models and actions, tightly coupled to the API layer itself.
  • Layered System: REST APIs have different layers of their architecture working together to build a hierarchy that helps create a more scalable and modular application.
* Disadvantages

    One of the disadvantages of RESTful APIs is that you can lose the ability to maintain state in            REST, such as within sessions. 







* RESTful Style HTTP methods (specific HTTP method for specific operation)

ex)
- POST : Create user  /users  (send a request to a collection) (User details are included in HTTP request body)
- GET : Read user details  /users/1 (send a request to a collection with and an Id of specific resource needed)
- PUT : Update user details  /users/1
- DELETE : Delete user  /users/1

* When an URL is same, HTTP method tells the intention of a request. (which operation to be performed)





# POSTMAN (HTTP client for testing API) (How to use, what is interceptor)


The process of creating HTTP request and expecting the corresponding HTTP response with Postman is much more convenient and faster since there is no need to have UI ready to be able to test web service API endpoints.


- POSTMAN INTERCEPTOR

Postman Interceptor helps you send requests which use browser cookies through the Postman app. 
It can also send headers which are normally restricted by Chrome but are critical for testing APIs.
.

# DTO DAO 

# JDBC / JPA (Hibernate) 


Comments

Popular posts from this blog

Portlet Edit Mode (Portlet preference) to replace Portlet configuration

GoGo Shell & What can be deleted in Liferay Instance