HTTP Methods Used in API

GET Method

  • Retrieves information from the system.
  • Used to fetch resources from a server specified by the given URI or URL.

POST Method

  • Creates new resources on the server.
  • Used for submitting data to be processed to a specified resource.

PUT Method

  • Updates the database with an entirely new entry or replaces the previous resource with a new one.
  • Used for creating a new resource or replacing an existing resource entirely.

PATCH Method

  • Partially updates an existing resource.
  • Used when only specific parts of a resource need to be modified, rather than replacing the entire resource.

DELETE Method

  • Removes an existing resource from the server.
  • Used to delete a resource identified by the given URI.

What is REST API in Node.js ?

REST (Representational State Transfer) is an architectural style for designing networked applications. A RESTful API is an API that adheres to the principles of REST, making it easy to interact with and understand. In this article, we’ll explore what REST API is in the context of Node.js, its principles, and how to create one.

Table of Content

  • Understanding REST API
  • Principles of REST API
  • HTTP Methods Used in API
  • Understanding PUT and PATCH
  • Conclusion

Similar Reads

Understanding REST API

A RESTful API is a web service that follows the principles of REST architecture. It uses standard HTTP methods (GET, POST, PUT, DELETE) to perform CRUD (Create, Read, Update, Delete) operations on resources, and data is typically transferred in JSON or XML format....

Principles of REST API

Client-Server Architecture: The client and server are separate entities that communicate via a stateless protocol (usually HTTP).Statelessness: Each request from the client to the server must contain all the information necessary to understand and process the request. The server does not store any client state between requests.Uniform Interface: Resources are identified by URIs (Uniform Resource Identifiers), and interactions with resources are performed using standard HTTP methods.Cacheability: Responses must define whether they are cacheable or not to improve performance.Layered System: The architecture can be composed of multiple layers, such as load balancers, proxies, and gateways, which can be used to improve scalability and security....

HTTP Methods Used in API

GET Method...

Understanding PUT and PATCH

PUT Method Example...

Approach

We will develop a RESTful API named “gfg-employees” to manage employee data. We’ll handle CRUD operations (Create, Read, Update, Delete) for employee records. Robo3T will serve as the database management tool, while Postman will facilitate sending HTTP requests. Below is a step-by-step guide for implementation....

Conclusion

A RESTful API in Node.js follows the principles of REST architecture, making it easy to design, develop, and consume web services. By adhering to the principles of REST, developers can create scalable, maintainable, and interoperable APIs that can be used across different platforms and devices. With Node.js and frameworks like Express, creating RESTful APIs has become straightforward, allowing developers to focus on building robust and efficient applications....