An overview of HTTP methods

Build web apps with NodeJS & Express

🕑 This lesson will take about 10 minutes

So far in this course, we have been using the GET method in our server code to specify what how our app should respond to different requests from the client for some content from the server. HTTP (HyperText Transfer Protocol) methods are the different types of methods that can be used for a client to request something from a server. The two most common HTTP methods used are GET and POST, however, there are some other methods that can be used too.

When a request is made from a client to a server, the HTTP method being used (to request or send responses from the server) is supplied in the request and it specifies the operation that the client has requested.

These are some of the HTTP methods that can be used:

  • GET method - requests a representation of a specified resource. Requests using the GET method should only retrieve data and should have no other effect. GET requests specify what is being requested in the URL (link). For example, the user may click on or type in a URL such as http://mywebsite.com/contact-us to get to the contact page on a website. When the server receives this request in the URL, it will handle the request and send a response (the contact page content). Another example is a simple Google search. When you search for something on Google, you will usually see the search term in the URL in the browser’s address bar. For example, if you searched for “cats” then you might see a URL like https://www.google.com/search?q=cats where the search query is actually specified in the URL. If there was other information in the GET request (such as searching for images or videos instead of pages, or searching for results from a specific location or timeframe, then this might also be visible in the URL). You should never use GET requests for sensitive information (eg. sending a username and password to the server to login a user) as this information will be visible in the URL for others to see. Use the POST method instead.

  • POST method - requests that the server accept data enclosed in the request. This type of request is often used to submit data in a form (such as a registration form, login form, shopping cart, etc). When a POST request is made, the data sent in the request is not included or visible in the URL.

  • PUT method - requests that the server accept data enclosed in the request as a modification to an existing object identified. If it does not exist then the PUT method should create one. DELETE method - requests that the server delete the resource specified.

In the next lesson, we will be looking at how to get data from the client that has been sent in GET and POST requests. Later in the course, you will learn how to create forms to submit data using POST requests.

Next lesson: Working with GET and POST request parameters