Different kinds of HTTP requests
Last Updated :
10 Apr, 2025
HTTP (Hypertext Transfer Protocol) specifies a collection of request methods to specify what action is to be performed on a particular resource. The most commonly used HTTP request methods are GET, POST, PUT, PATCH, and DELETE. These are equivalent to the CRUD operations (create, read, update, and delete).
HTTP Requests
HTTP Requests are the message sent by the client to request data from the server or to perform some actions. Different HTTP requests are:
- GET: GET request is used to read/retrieve data from a web server. GET returns an HTTP status code of 200 (OK) if the data is successfully retrieved from the server.
- POST: POST request is used to send data (file, form data, etc.) to the server. On successful creation, it returns an HTTP status code of 201.
- PUT: A PUT request is used to modify the data on the server. It replaces the entire content at a particular location with data that is passed in the body payload. If there are no resources that match the request, it will generate one.
- PATCH: PATCH is similar to PUT request, but the only difference is, it modifies a part of the data. It will only replace the content that you want to update.
- DELETE: A DELETE request is used to delete the data on the server at a specified location.
Now, let's understand all of these request methods by example. We have set up a small application that includes a NodeJS server and MongoDB database. NodeJS server will handle all the requests and return back an appropriate response.
Project Setup and Modules Installation
Step 1: To start a NodeJS application, create a folder called RestAPI and run the following command.
npm init -y
Step 2: Using the following command, install the required npm packages.
npm install express body-parser mongoose
Step 3: In your project directory, create a file called index.js.
Project Structure:
Our project directory should now look like this.
Implementing GET Request
1. To make a GET request, paste the following URL in the Enter request URL text box of the postman.
https://api.github.com/gists
2. Go to the headers tab and add a header called "Accept" and set it to:
application/vnd.github.v3+json
3. At the bottom, you can see the response formatted as JSON.
Making a POST Request
Steps to make a POST request are:
Step 1: Login to your GitHub account and go to Settings/Developer settings >> Personal access tokens.
Step 2: Click on Generate new token button.
Step 3: Give your token a name and select the scope Create gists.
Step 4: Click on Generate token button.
Step 5: Copy the access code and paste it somewhere.
Step 6: Finally, we are ready to make a POST request. Paste the same URL we used above in GET request in the input field of the postman.
Step 7: In the headers tab, add "Accept" as a header and set it to:
application/vnd.github.v3+json
Step 8: Go to the body tab, choose the content type to JSON and choose the data format as raw.
Step 9: Paste the following in the body tab.
{
"public": true,
"files": {
"newgist.txt": {
"content": "Adding a GIST via the API!!"
}
}
}
In the above text first, we have set the public flag to true which indicates that the gist we are creating is public. Second, we have defined the files property, whose value is another object with a key of the name of your new gist. Inside the new gist object, we have another key called content, whose value is whatever you want to write in your gist.
Step 10: Go to the authorization tab and choose the authorization type to Basic Auth. Type your GitHub username and generated access token in the username and password field, respectively.
Step 11: Click on the send button, and you will get the response.
Making a PATCH Request
Now we update the gist we just created. To make a PATCH request, follow the given steps:
Step 1: Find the ID of your created gist by going to
https://gist.github.com
Step 2: Paste the following URL in the input field of the Postman.
https://api.github.com/gists/{gist_id}
Step 3: In the headers tab, add "Accept" as a header and set it to
application/vnd.github.v3+json
Step 4: Go to the body tab and add the description of the created gist.
{
"description": this is my newly created gist,
"files": {
"newgist.txt": {
"content": "Adding a GIST via the API!!"
}
}
}
Step 5: Go to the authorization tab and choose the authorization type to Basic Auth. Type your GitHub username and generated access token in the username and password field, respectively.
Step 6: Click on the send button and refresh your gist to see the updated description.
Making a DELETE Request
Step 1: Paste the following URL in the input field of the Postman.
https://api.github.com/gists/{gist_id}
Step 2: In the headers tab, add accept as a header and set it to
application/vnd.github.v3+json
Step 3: Click on the send button and your gist gets successfully deleted.
Summary
HTTP requests include methods like GET (retrieving data), POST (creating resources), PUT (updating resources), DELETE (removing resources), and PATCH (partial updates). These methods allow clients to interact with server resources, each serving distinct roles in web development.
Similar Reads
Explain Different Types of HTTP Request
Hypertext Transfer Protocol (HTTP) defines a variety of request methods to describe what action is to be done on a certain resource. The most often used HTTP request methods are GET, POST, PUT, PATCH, and DELETE. Let's understand the use cases of HTTP requests: GET: A GET request reads or retrieves
5 min read
Node.js https.request() Function
Https request function in Node is used to make the http request over secure http or https. It provide more control to the request like setting headers, http methods, adding request data and handle the responses.https.request(options, callback)It is a part of https module and allows to send different
2 min read
Make HTTP requests in Angular?
In Angular, making HTTP requests involves communicating with a server to fetch or send data over the internet. It's like asking for information from a website or sending information to it. Angular provides a built-in module called HttpClientModule, which simplifies the process of making HTTP request
4 min read
Servlet - Client HTTP Request
When the user wants some information, he/she will request the information through the browser. Then the browser will put a request for a web page to the webserver. It sends the request information to the webserver which cannot be read directly because this information will be part of the header of t
3 min read
Explain HTTP Request in Backbone.js
Backbone.js is a compact library used to organize JavaScript code. An MVC/MV* framework is another term for it. If MVC is unfamiliar to you, it is just a technique for designing user interfaces. The creation of a program's user interface is made considerably easier by JavaScript functions. BackboneJ
4 min read
How to make HTTP requests in Node ?
In the world of REST API, making HTTP requests is the core functionality of modern technology. Many developers learn it when they land in a new environment. Various open-source libraries including NodeJS built-in HTTP and HTTPS modules can be used to make network requests from NodeJS.There are many
4 min read
HTTP Request vs HapiJS Request in Node.js
Node.js: Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and itâs not a programming language. Most of the people are confused and understand itâs a framework or a programming languag
3 min read
User Agent in Python Request
The User-Agent (UA) string is one of the most important factors in website identification in Web Scraping. It is like a fingerprint that a client or targeted website can identify. With the help of this, you can retrieve the data by shuffling the user agent into Python requests. It typically includes
5 min read
Creating Your Own Node HTTP Request Router
In Node, if we want to build our own custom HTTP request router then we can create it by handling the incoming requests and directing them to the specific endpoints. Using this routing process, allows us to define the different actions or responses that are based on the requested URLs. In this artic
2 min read
Flask HTTP methods, handle GET & POST requests
In this article, we are going to learn about how to handle GET and POST requests of the flask HTTP methods in Python. HTTP Protocol is necessary for data communication. In the context of the World Wide Web, an HTTP method is a request method that a client (e.g. a web browser) can use when making a r
6 min read