Different kinds of HTTP requests
Last Updated :
07 Jan, 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 the 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.
Become a Full-Stack Developer and also get 90% fee refund on completing 90% course in 90 days! Take the Three 90 Challenge today.
After successfully processing refunds worth over INR 5 Cr, GeeksforGeeks is back with the Three 90 challenge and this is your chance to upskill and get 90% refund. What more motivation do you need? Start the challenge right away!
Similar Reads
Different kinds of HTTP requests
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 d
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 differen
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
How to create different post request using Node.js ?
A POST request is one of the important requests in all HTTP requests. This request is used for storing the data on the WebServer. For Eg File uploading is a common example of a post request. There are many approached to perform an HTTP POST request in Node.js. Various open-source libraries are also
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 HTTP POST requests work in Node ?
The HTTP POST method is employed by the World Wide Web to send data to a server. This request method is characterized by the inclusion of data in the request body, and the type of this body is specified by the Content-Type header. Express.js, a web application framework for Node, facilitates the cre
2 min read
How to Send an HTTP POST Request in JS?
We are going to send an API HTTP POST request in JavaScript using fetch API. The FetchAPI is a built-in method that takes in one compulsory parameter: the endpoint (API URL). While the other parameters may not be necessary when making a GET request, they are very useful for the POST HTTP request. Th
2 min read
Explain the different ready states of a request in AJAX
In this article, we are going to learn about the readyStates of a request in AJAX. readyState is an XMLHttpRequest property. There are five ready states of a request as listed below: readyState=0readyState=1readyState=2readyState=3readyState=4How to use readyState? Before using the readyState, we ne
5 min read
HTTP headers | Upgrade-Insecure-Requests
The HTTP header Upgrade-Insecure-Requests is a request type header. It sends a signal to the server expressing the client’s preference for an encrypted and authenticated response, and it can successfully handle the upgrade-insecure-requests HTTP headers Content-Security-Policy directive. Syntax: Upg
1 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
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
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
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
Structure of HTTP request in Postman
Postman is a powerful tool that simplifies the process of making HTTP requests for testing APIs. Understanding the structure of a typical HTTP request in Postman is fundamental for everyone who want to test endpoints. In this article, we'll break down the key components of an HTTP request in Postman
3 min read
How Are Parameters Sent In An HTTP POST Request?
HTTP POST requests are widely used in web development to send data from a client to a server. Whether you're submitting a form, uploading a file, or sending JSON data via an API, understanding how parameters are sent in an HTTP POST request is important. In this article, we’ll explore how are parame
5 min read
How to find the total number of HTTP requests ?
In this article, we will find the total number of HTTP requests through various approaches and methods like implementing server-side tracking by using PHP session variables or by analyzing the server logs to count and aggregate the incoming requests to the web application. By finding the total count
3 min read
Difference between HTTP GET and POST Methods
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. This article covers the 2 most common HTTP request methods, i.e. the GET
5 min read
How can you view different types of responses in Postman?
Postman is a powerful tool that allows you to test and interact with APIs by sending requests and examining the responses. Responses from APIs can come in various formats, and understanding how to view these different types of responses is important for effective API development and debugging. Prere
3 min read