Design Restful WebServices — Part 1
Design API like end user will consume It
Photo by Fahim Muntashir on Unsplash
HTTP is an application-level protocol that defines the operation between client and server. There is a difference between designing Restful API & Designing API, which also uses HTTP protocols and JSON/XML for data transfer.
REST is an acronym for R epresentational S tate T ransfer, an architectural style for distributed hypermedia systems.
In this protocol, methods such as GET , POST , PUT , and DELETE operations that act on resources.
This protocol eliminates the need for you to invent application-specific operations such as createOrder , getStatus , updateStatus , getUserInfoById, etc.
A Web API or Web Service that follows this type of architecture is known as a RESTful API
Problem 1:
You want to know how to apply those protocols GET, POST, PUT, PATCH, and DELETE on resources to achieve Restful Architecture Style.
Solution:
When you define the resource like Customer, Order, User, etc, use GET to get a resource representation, PUT to update a resource, DELETE to delete a resource, and POST to create a resource.
Role of Idempotent & Safe HTTP Methods in Restful Web Services & Implementation
What is idempotent in the HTTP Method?
We call an HTTP method idempotent if that method does not create any side effects or alter the state of the server even if we send the same request many times.
GET — if we call get request on a resource many times it will not change the state of the resource, it will return the result of how many times we call it without doing any side effects
POST — If we call a post request multiple times it will create a new resource every time. For Example, if we send create customer resource multiple times it will every time generate a new customer and save to DB.
If we Implement correctly, the GET, HEAD, PUT, and DELETE methods should be idempotent in Restful API Design. If we violate that rule then we can’t call it RESTful Standard API Design.
In an idempotent check, only Backend Server State is considered. Not the Status Code.
For Example
The first Call of DELETE Return 200 but the Second call will return 404.
Happy reading… 😁😃 Rajdeep Das | LinkedIn
Top comments (0)