
Lesson Description
The "User Routes" 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 reviews creating user routes in Express, stressing practice and rewriting code. He covers creating, updating, and deleting users, admin and authentication considerations, and additional CRUD operations for completeness.
Transcript from the "User Routes" Lesson
[00:00:00]
>> Speaker 1: And then we will do the same one for the User Routes Let's do that Sounds very much the same, honestly But it's a good exercise to write it again Imports Router from Express Const router Honestly, just writing stuff over and over again There used to be this app a long time ago that taught you how to type by taking an open-source project like jQuery
[00:00:00]
You had to type along all the characters, and if you got one character wrong, it wouldn't move forward It would highlight the code as you type, so you were technically writing code without needing to know how to code It was just teaching you how to type by writing code and working with open-source projects
[00:00:00]
That's how I learned a lot about open-source projects and typing So, Router Let's say we want to get all the users, so we'll do that And that's going to be a 200 status code, so we've got all the users Then let's say we want to get a user with a specific ID Got that user
[00:00:00]
We have the ability to create users, but you have to think: when would you ever create a user that wasn't signing up This would be like an admin dashboard using this API, where for some reason you wanted to create a user without that user having to sign up This is what that route would be for
[00:00:00]
You might add extra permissions so only the admin dashboard can access this route In a traditional setup, you wouldn't have a route where anybody can just make a user and bypass all your authentication logic That's not going to work I'll add the ability to update a user with a PUT request
[00:00:00]
And these would be the updated user details You could also delete a user if needed I'll export this I have some extra examples in the code that show a complete CRUD implementation, but we're not going to write handlers for all of that because we'd be here all day.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops