In this video, explore how to chain multiple Express methods for a single path and refactor the current index to demonstrates this technique.
- [Instructor] As your APIs get more complicated,…you might need to refactor your code to make it cleaner…and chaining multiple methods into a single block of code…for a specific path,…and chaining will do that.…Let me demonstrate.…So the first thing we need to do…is to get a few of those calls in the same path.…So let's change newItem to item,…and let's make sure post is still working, yup.…
And then let's, for the images,…change that for item, as well.…And instead of doing the res.download,…let's do the response here…and make sure the response also reflects the type of call,…so let's do a get request,…item route on port.…Boom, good to go.…And let's also get…this one here.…
And we'll change this one to put.…And then just change it to put, as well, here.…We got a put call,…a get call,…and then a delete call with all the same path,…so we could probably save a few lines…if we change this with chaining.…So let's refactor that.…So let me grab the first one here,…and let's actually start from get,…and let's basically close your path within a method.…
- Creating a basic data endpoint
- Routing with Express
- Adding a static route for file serving
- Basic middleware with Express
- Built-in middleware and error-handling middleware
- Debugging in an Express application
- Security best practices with Express
Skill Level Beginner
Building RESTful Web APIs with Node.js and Expresswith Emmanuel Henri1h 40m Intermediate
1. Setting Up Express
2. Getting Started
3. Routing with Express
4. Middleware with Express
5. Advanced Topics in Express
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.