**Hola guys , In this section , we will learn about RESTFUL APIs . This section will be like full of theory , so be patient and learn . **
What is Rest APIs ?
A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. -By RedHat
lets separate the Rest APIs as REST and API.
REST stands for Representational State Transfer .
API stands for Application Programming Interface .
Express.js is a popular web framework for building RESTful APIs in Node.js. RESTful APIs are APIs that follow the REST (Representational State Transfer) architectural style, which is a set of constraints and best practices for creating web services. RESTful APIs are designed to be easy to use and maintain, and are often used to provide a simple interface for interacting with a database or other backend system.
I wish you to learn more about REST APIs here.
Anatomy of REST APIs
The anatomy of a RESTful API built with Express.js typically consists of the following components:
Routes: A route is a URL pattern that maps to a specific function in the API. In Express.js, routes are defined using methods like
app.delete(), which correspond to the HTTP methods GET, POST, PUT, and DELETE, respectively.
Controllers: A controller is a function that handles a request and produces a response. In an Express.js API, controllers are often responsible for handling requests to a specific route, and may make use of models (described below) to perform actions on the backend.
Models: A model is a representation of a data object, such as a user or a product. In an Express.js API, models are often used to interact with a database or other persistent storage system to create, read, update, and delete data.
Middleware: Middleware is code that runs before or after a request is handled by a controller. It can be used to perform tasks such as validation, authentication, and error handling. In Express.js, middleware functions are defined using the
Overall, the structure of an Express.js API is designed to be flexible and modular, allowing developers to easily add and modify routes, controllers, models, and middleware as needed.
Any REST request includes four essential parts:
An HTTP method describes what is to be done with a resource. There are four basic methods also named CRUD operations:
POST to Create a resource
GET to Retrieve a resource
PUT to Update a resource
DELETE to Delete a resource
Endpoint (or route)
It is the URL that you have requested. It includes a Uniform Resource Identifier (URI) that indicates where and how to locate the resource on the Internet. A Unique Resource Location (URL), which serves as a complete web address, is the most common type of URI.
Keep information that is relevant to both the client and the server. Headers primarily provide authentication data, such as an API key, the name or IP address of the computer on which the server is installed, and response format information.
It is used to send additional data to the server. For example, you might want to add or replace some data.
Thank you guys, please subscribe to my blog. so that you will get all my posts and blogs.
Did you find this article valuable?
Support HARRISH G by becoming a sponsor. Any amount is appreciated!