HTTP Methods Explained

karaluton

Kara Luton

Posted on August 11, 2020

HTTP Methods Explained

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.

💖 💪 🙅 🚩
karaluton
Kara Luton

Posted on August 11, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related