
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]
>> Scott Moss: 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, so.
[00:00:22]
But it's a good exercise to write it again, so. Oops ports. Router from. Express.
[00:00:39]
Express. Constant router. And I mean honestly just writing stuff over and over again. There used to be this app a long time ago where it was a it was it was an app that taught you how to type, but the way that they did it was they would take an Open Source project like jQuery.
[00:00:54]
There used to be this app a long time ago where it was a it was it was an app that taught you how to type, but the way that they did it was they would take an Open Source project like jQuery. And you had to type along all the characters if you got one character wrong it wouldn't move forward and it would like highlight the code as you type so you were technically writing code, but you didn't know how to, you didn't need to know how to code to do this. It was just teaching you how to type by writing code and taking your Open Source project and I used to do that a lot and that's how I learned a lot of the Open Source projects and learned how to type was just doing that. So router.
[00:01:12]
So router. Git, so let's say we wanna get, All the users, so we'll do that. And that's gonna be a 200, so we got all the users. And then let's say we want to get a user with a specific ID, so we'll say giving that user with that ID.
[00:01:38]
And then let's say we want to get a user with a specific ID, so we'll say giving that user with that ID. Got user. We have the ability to like create users, but then you gotta think like when would you ever create a user that wasn't signing up? This would be like if you got like an admin dashboard that was also using this API and for some reason you wanted to like create a user inside that admin dashboard without that user having to Go and sign up for whatever reason, this is what that route would be for.
[00:01:57]
This would be like if you got like an admin dashboard that was also using this API and for some reason you wanted to like create a user inside that admin dashboard without that user having to Go and sign up for whatever reason, this is what that route would be for. And you might add extra permissions and stuff, so only the admin dashboard can access this route and things like that, but. Yeah, in a traditional cut out, you wouldn't have a route where anybody can just make a user and bypass all your business logic for authentication that just. Yeah, good luck that's not gonna happen, but Yeah, I'm not gonna put that.
[00:02:15]
Yeah, good luck that's not gonna happen, but Yeah, I'm not gonna put that. We can put that on, but I'm not gonna put it cause we're not gonna use that. I'm gonna say, do be able to update a user though, so I'll say put. And I'll take this.
[00:02:25]
And I'll take this. These are updated. Cool. And then yeah, you could delete a user, why not.
[00:02:59]
And then yeah, you could delete a user, why not. Cool. I mean that's Export this. I have some extra ones that's like in the code, you don't have to add those.
[00:03:19]
I have some extra ones that's like in the code, you don't have to add those. Those are just there to show you a complete example of. CRUD, we're not, you can write them, but it's not gonna hurt you, but when we go do like the handlers, we probably won't write handlers for all that stuff cause we would
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops