Loading
Lesson 12
Courses / Getting Started with Express (Learn Nodejs Backend JSON REST API Web Development)
End of the Express Course Review

Summary

Course Summary

Introduction

  • Congratulations on completing the course!
  • We reviewed everything learned during the course.

Key Topics Covered

  1. Project Setup

    • Generated a new project using NPM.
    • Installed Express, a Node.js web framework, used to build a RESTful JSON API.
  2. Bookstore Example

    • Built an example API for a bookstore, focusing on managing books with properties like title.
  3. Express Basics

    • Set up an Express application.
    • Used app.use for middleware application.
    • Learned about body parser and Express JSON middleware to access request body data.
  4. HTTP Methods

    • Implemented GET, POST, PUT, and DELETE routes.
    • Defined routes using HTTP verbs and endpoints.
    • Processed requests and sent responses using res.send.
  5. Routing and Parameters

    • Handled route parameters with req.params and recommended parsing those values.
    • Managed status codes, including:
      • Return 404 for not found errors.
      • 204 No Content for successful deletions.
      • 500 Internal Server Error for general errors.
  6. Validation and Error Handling

    • Emphasized the importance of validation for request bodies.
    • Encouraged filtering out unwanted request properties.
  7. Server Setup

    • Used app.listen() to run the server on localhost:3000.

Further Recommendations

  • Explore more middleware, such as passport.js for authentication.
  • Improve the code by organizing it into a scalable structure, possibly following the MVC (Model-View-Controller) pattern.
  • Conduct further research into advanced Express topics and best practices.

Conclusion

  • Thank you for participating in the course!
  • You're encouraged to continue learning and building upon this foundation.

Video Transcript

Hello everybody, we have reached the end of the course. So congratulations on getting here. So let's review everything we did in this course. So we learned how to generate a new project using NPM. We installed Express. Express is a Node.js web framework. We use it in our case to build a RESTful JSON API. We use an example of a bookstore where you have many books and those books each have a title. They could have many more properties where we focus on just learning the Express and how to do the routing and all that kind of stuff, how to handle the data and call a fake ORM-like module. That's the book module we made to do operations on the hard code, the data that we thought of it as our database. So we learned to use Express. Set it up with a basic Express. You have to call Express to make the app. Then the app is pretty much where everything is going to be acted upon. You call app.use to apply any middle errors. You learn about the body parser and the Express JSON middle errors to allow us to get a rack.body available inside a route so we can see the contents of the request body formatted from JSON to the actual JavaScript object or list. We learned about how to do a get, a post, a put and delete routes using the Express. Usually the usual way to define a route is you do the verb. HTTP verb is going to be the method you call. First argument is the path, the endpoint to this API resource. Then the second is always going to be what you're going to do when this request comes. It's where you define typically your response. You do some processing and then you respond to the request. It's always with the rack as its first parameter and the rest as the second parameter. Those correspond to request and response respectively. We learned about res.send to send any kind of response back to the client. Alert various ways of parsing the request route parameters. Rack.params, remember it's a string so if you have numbers in there you should definitely parse them. Then we learned about how to change the status code. In this case if we could not find the record we should always make sure to return a response with the status code 404 and with some friendly message for the client. Otherwise everything goes well just send the actual book object in this case in JSON format. Then we learned how to create a book. Very simple. We didn't do any validation in this course but you should definitely validate all these request body parameters that come in. You should also filter out the unwanted ones in case some guy is trying to mess with your system and try to add new stuff that could have some bad consequences. I don't know. Anyway. We did update, same thing 404 and all that stuff. Then finally we did the delete. We went a little bit overboard in the delete because we wanted to start thinking about special cases and error handling. Since we are using a card coded database like structure it's not really a database and it's not a sync asynchronous. We don't have any issues but you would probably have some issues to solve if you were an actual database. Learn to send the status tool for no content in case we destroy something and it succeeds and there's no content to be returned. Learn about 500 internal server error just in case something general error would happen. This is not recommended to be used anyway. You would use something like 422 bad request. I don't remember the name of 422. It's either bad request or something else. Anyway 400 type, 4XX type errors is when the actual server side, the client sends something that the server does not think it was not in the right format. You should read more about status code on your own. Anyway. Yeah. So we learned around and everything. Make sure to call the app.list so you are actually running the server and put a friendly messaging to the server so he can know what part is running. In all cases we define the part 3000 so we go to localhost 3000 every time we want to access our API. So this course was just an introduction to express. There's a lot more you can build upon. You should definitely look into the more middlewares for authentication, that kind of stuff. I recommend passport.js and that kind of stuff. Also you should definitely look into improving the code base. In our case we put everything in one file but that's not really good in the long term for scale as your app grows and grows and grows. So you define, you could follow the kind of MVC model view controller like directory structure where each of the routes go under a, we call it controller. And we can separate all the routes depending on for each resource and the kind of stuff. So you can do your own research and learn about that as you go on advanced topics of the express framework. Okay that is all for the course and thank you so much. Congratulations.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: