API Design in Node.js, v5

HTTP Verbs & RESTful Route Patterns

Scott Moss
Netflix
API Design in Node.js, v5

Lesson Description

The "HTTP Verbs & RESTful Route Patterns" Lesson is part of the full, API Design in Node.js, v5 course featured in this preview video. Here's what you'd learn in this lesson:

Scott explains common HTTP methods like GET, POST, PUT, PATCH, and DELETE, their purposes in APIs, and the effect of each request. He also touches on REST principles, CRUD routes, and the flexibility of REST compared to GraphQL.

Preview
Close

Transcript from the "HTTP Verbs & RESTful Route Patterns" Lesson

[00:00:00]
>> Speaker 1: Cool, let's do some routing We talked about routing a little bit It's essentially just a combination of a verb and a pattern, right So first, let's understand these verbs or what you might also hear as methods

[00:00:00]
HTTP itself has a few methods They're actually in the spec You can check the HTTP spec Here we go, HTTP request methods We're not going to talk about all these methods because they don't really relate to what we're doing with an API, but the ones that matter, we will discuss

[00:00:00]
The ones that really matter are going to be GET So if you ever typed a URL into a browser and hit enter, you did a GET request That's literally what a GET request is

[00:00:00]
Going to a website is doing a GET request It's the same thing So for that reason, most GET requests typically return HTML statistically because most people just go to websites

[00:00:00]
Those things return HTML, but they can also return JSON Our API is a JSON API, so we're returning JSON, but statistically, I would say most GET requests probably return HTML

[00:00:00]
Its purpose is to get things That's why it's called GET Typically get many things, not get one thing Well, I guess it really depends on the URL, but it's typically meant to get something from the server

[00:00:00]
POST is "I want to create something on the server." So I want to sign up, create a new habit, log a new thing, make a new post on LinkedIn

[00:00:00]
That's why posts on social networks are probably called posts because they're doing a POST in the API You're literally posting something to the database

[00:00:00]
A PUT is a type of update It's more of a replace – I want to find something on your server and replace it entirely with a new thing Pretty much everything but the ID is going to change

[00:00:00]
A PATCH is what you would probably think of as an update Like, I partially want to update some fields on something in the database – change my username, change my email, update a timestamp

[00:00:00]
A DELETE is exactly what it sounds like: to delete something, to remove a resource from a database I'm using "database" here, but you don't need a database for any of this to make sense

[00:00:00]
The whole point of an API is typically to sit in front of a database, but these are verbs to describe intent These verbs help other systems and clients understand the intent of the request

[00:00:00]
A lot of software makes assumptions based on that intent Browsers would do specific things for GET, POST, PUT, PATCH, and DELETE – how they show things, what status codes they expect to get back

[00:00:00]
For the most part, these are the five main methods There's probably another one called the OPTIONS header, but we'll talk about that later

[00:00:00]
If you use GraphQL, you really only care about one or maybe two of these methods These verbs are just there to help describe intent, but you're not strictly required to follow them exactly

[00:00:00]
Let's talk about REST Who knows what REST is I'll be honest – I've been using REST my whole life and still don't completely understand it

[00:00:00]
There are so many flavors and ways people implement it REST typically works like this: For every resource a client can access (like a user, habit, entry, or tag), you'll have CRUD routes

[00:00:00]
CRUD stands for Create, Read, Update, and Delete This doesn't mean you'll only have four routes, but these are the four primary actions you can do on a resource

[00:00:00]
[The transcript continues with the detailed explanation of REST routes and methods, maintaining the speaker's conversational style and technical explanations.]

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now