loading...

HTTP Methods Explained

karaluton profile image Kara Luton ・2 min read

As a frontend developer you'll most likely be interacting with a lot of APIs. It's especially important to understand the different methods you can use when interacting with an API and the responses you receive back.

We'll be going over HTTP methods for REST APIs. So first let's talk about what in the world a REST API is.

REST stands for "representational state transfer" and is a set of rules developers need to follow when they create their API. REST APIs have five types of methods aka the type of request you send to the server.

Those methods are the following:

  1. GET
  2. POST
  3. PUT
  4. PATCH
  5. DELETE

Each method performs one of four possible actions:

  1. Create
  2. Read
  3. Update
  4. Delete

You may have heard these actions referred to as CRUD before.

Let's dive into each method and what responses you get for both a successful and invalid request.

GET

What it does: Requests retrieve resource information.
Action: Read
Successful response: 200 OK
Error response: 404 not found

POST

What it does: The server creates a new entry in a database
Action: Create
Successful response: 201 Created
Error response: 404 not found or 409 conflict - if the resource already exists

PUT

What it does: Updates an existing resource
Action: Update
Successful response: 200 OK
Error response: 204 no content, 404 not found or 405 method not allowed

PATCH

What it does: Very similar to PUT but makes a partial update on a resource
Action: Update
Successful response: 200 OK
Error response: 204 no content, 404 not found or 405 method not allowed

DELETE

What it does: Deletes resources
Action: Delete
Successful response: 200 OK
Error response: 404 not found or 405 method not allowed

A quick summary of the responses you may see is that anything in the 200 range means the request was successful, anything in the 400 range means an error has originated from the client and the 500 range means an error has originated from the server.


Have you stumbled upon any cool APIs that you've worked with before? I'd love to hear about them in the comments!

Be sure to follow me on Twitter for lots of posts about tech, and if I'm being honest, lots of posts about dogs too.

Posted on by:

karaluton profile

Kara Luton

@karaluton

From tutus to tech. Ballerina ➡️ music publicist ➡️ software engineer. Nashville Women Programmers organizer.

Discussion

pic
Editor guide
 

Hi, very good explanation.

Currenly I use APIs all the time, because we need connect the ERP with other services like invoices, reports, triggers. My question is what happend when you want to use GET but need to send a object (json) in the body. I think you can't send objects with GET then you need to use POST. is correct?

Can you use POST to read or remove or is a bad practices?

I used Signaturit to sign contracts or importants documents and their API is very easy to implement. Is very helpful in Europe because this company complies with European laws.

Regards.

 

Hi Jesús! If I'm understanding the question correctly, you'll need to do two separate requests. One with GET to retrieve the information you're requesting and then a POST to update that information.

 

Great resource. I'll update my HTTP methods one-liner description in Postwoman with these.

GitHub logo hoppscotch / hoppscotch

👽 A free, fast and beautiful API request builder used by 75k+ developers. https://hoppscotch.io

hoppscotch.io logo

A free, fast and beautiful API request builder

Helps you create requests faster, saving precious time on development - Subscribe

Travis Build Status GitHub release Website Contributions welcome Financial Contributors on Open Collective Donate on PayPal Chat on Telegram Chat on Discord Tweet


Built with ❤︎ by
liyasthomas and
contributors




Chat: Telegram, Discord

Donate: GitHub Sponsors, Open Collective, Patreon, PayPal

Screenshot1
Table of contents

Features

❤️ Lightweight: Crafted with minimalistic UI design.

⚡️ Fast: Send requests and get/copy responses in real-time.

Methods:

  • GET - Retrieve information about the REST API resource
  • HEAD - Retrieve response headers identical to those of a GET request, but without the response body.
  • POST - Create a REST API resource
  • PUT - Update a REST API resource
  • DELETE - Delete a REST…




 

Thank you, that’s awesome!

 

Kudos for breaking this down in such a nice and legible way for beginners. I was happy with all of these and would have loved such a crisp and succinct break down when I was starting.

 

Thanks so much!