Created
Nov 19, 2025
Last Modified
4 months ago

REST API

REST API (Representational State Transfer API)

19 Nov 2025

REST API is a type of API that allows communication between different systems over the Internet. It works by sending requests and receiving responses, typically in JSON format, between the client and server.

A request is sent from the client to the server via a web URL using one of the HTTP methods. The server responds with the requested resource, which could be HTML, XML, image, or JSON (JSON is the most commonly used format).

REST APIs are model-based web services. These methods map to CRUD operations:

  • Create

  • Read

  • Update

  • Delete


Common HTTP Methods Used in REST API

GET Method: (READ)

The HTTP GET method is used to read the representation of a resource in a safe way. GET returns a representation in XML or JSON.

  • Success Response: HTTP 200 OK

  • Error Response: 404 Not Found or 400 Bad Request


POST Method: (Create)

The POST method is commonly used to create new resources. It is often used to create web or subordinate resources related to a parent resource.

  • Success Response: HTTP 201 Created along with a Location header pointing to the newly created resource


PUT Method: (Update/Create)

PUT is used to update or create a resource on the server. When using PUT, the entire resource is sent in the request body and it replaces the current resource at the specified URL. If the resource does not exist, it creates a new one.


PATCH Method: (Partial Update)

PATCH is used to update a resource on the server partially. Unlike PUT, PATCH only requires the fields that need to be updated to be sent in the request body. It modifies the specific part of the resource rather than replacing the entire resource.

Difference Between PUT and PATCH:

PUT

PATCH

Replaces entire resource

Update only specified field

Must send full data

Only sends changes.

Example: Updating the user's entire profile.

Example: Changing just the user's image.


DELETE Method: (Delete)

DELETE is used to delete a resource identified by a URL.

  • Success Response: HTTP 200 OK along with a response body

Difference between PUT and PATCH:


Real-World Examples of REST API

  • Social Media: Integrating third-party platforms like Facebook and Instagram for login, streaming, and posting.

  • E-commerce: Managing products, processing payments, handling orders, and customer management.

  • Weather Forecasting: Fetching weather data from external sources to provide real-time updates.

  • Location Services: GPS tracking, real-time location updates, and location-based services like finding nearby places.