DEV Community

Rajdeep Das
Rajdeep Das

Posted on • Originally published at rajdeep-das.Medium on

Design Restful WebServices — Part 1

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.


HTTP Method Table

Happy reading… 😁😃 Rajdeep Das | LinkedIn

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay