HTTP Request Methods

Last Updated Jul 09, 2021

What are HTTP Request Methods?

The Internet is vast, but it mostly amounts to resources hosted on servers. These resources are accessed via HTTP (Hyper Text Transfer Protocol), which provides an agreed-upon language for requests and responses. A message sent by the client to the server is known as an HTTP request. Clients can use different methods of interacting with servers, which are called HTTP request methods. These are always upper case verbs, and tell the server what we want to do.

Try an HTTP GET Request

A GET request reads information from a record in the database. Typing `curl https://jsonplaceholder.typicode.com/posts` and ENTER in your terminal should return a status code and content that looks like this:


StatusCode        : 200
StatusDescription : OK
Content           : [
                      {
                        "userId": 1,
                        "id": 1,
                        "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
                        "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita ...

So, what happened in this GET request? The client (us) requested information from the API at `https://jsonplaceholder.typicode.com`, specifically the endpoint at `/posts`, by sending a JSON card with a GET request to the API. The API authenticated the request and made a call to the server. The server returned the requested information to the API, and the API sent the JSON card with the requested information back to the client (us).  

What are the most common HTTP Request Methods?

Try some of the other most common HTTP request methods in your terminal with cURL:

  • PUT- This operation changes a record’s information in the database. `curl -X PUT -d "userId=1&title=Something else&body=A new body" https://jsonplaceholder.typicode.com/posts/1`
  • POST - This operation creates a new record in the database. `curl -X POST -d "userId=5&title=Stuff and Things&body=An amazing blog post about both stuff and things." https://jsonplaceholder.typicode.com/posts`
  • PATCH - This operation updates an existing resource, but does not require sending the entire body with the request. `curl -X PATCH -d "title='Only change the title'" https://jsonplaceholder.typicode.com/posts/1`
  • DELETE - This operation removes a record from the database. `curl -X DELETE https://jsonplaceholder.typicode.com/posts/1`

Note that we're using JSON Placeholder to test their API endpoints. Thanks for this great resource!

More HTTP Request Methods

The above HTTP request methods are not all of the possible methods. There are a[few others to keep in mind that are useful in testing and debugging:

  • HEAD - This operation retrieves a resource's header and status without the rest of the resource, and is a good way of testing a resource before issuing a request. `curl HEAD https://www.abstractapi.com`
  • OPTIONS - This operation informs the client of what communication options are available with the resource. `curl OPTIONS https://www.abstractapi.com`

Conclusion

HTTP requests are how clients modify resources via APIs. Knowing how to use these requests effectively allows you to access any API you have authorization for. Just as authors use the same language we do to write incredible books, Google Maps is made with these same fundamental components of HTTP request methods. With a little practice, you'll do great things, too.