Course info

Rating

(867)

Level

Intermediate

Updated

Apr 14, 2015

Duration

2h 4m

Description

Node.js is a simple and powerful tool for backend development. When combined with express, you can create lightweight, fast, scalable APIs quickly and simply. In this course, we will walk through how to stand up a lightweight Express server serving truly RESTful services using Node.js, Mongoose, and MongoDB. We will implement all of the RESTful verbs to get, add, and update data from our service. We will also spend some time working through unit and end to end integration tests for our services.

About the author

Jonathan Mills is a JavaScript and Node.js expert working mostly in the MEAN Stack with individuals and companies to help build their technical skills to cope with the constantly changing landscape of software development. He is also an ASP.NET insider and an international speaker focusing on JavaScript both in the browser and on the server.

Section Introduction Transcripts

What Is REST?Welcome to RESTful Web Services with Node. js and Express. I'm Jonathan Mills from Pluralsight. In this module we're going to talk about how to build a RESTful API with Node and Express. We'll start out by talking about what REST really is and then we'll setup a Node and Express environment so we can get started. We'll implement all of the REST verbs, get, put, post, patch, delete, and when you would use the different verbs. We'll wire everything up to MongoDB using Mongoose for our backend. We'll unit test with Mocha and Sinon. js, Sinon will be used for our mocking, and then we'll end with a conversation on hypermedia and why links in our APIs help our API consumers navigate our API.

Getting DataThis is Jon Mills and in this module we're going to talk about getting data from our API. Now we've started building out a RESTful API with Node and Express. We haven't done a whole lot yet, we've just setup the basic structure and we'll re-cover that here in just a second, but what we're going to do in this module is implement the HTTP Get verb that allows users to pull data from our API. We're going to allow them to pull a list of items or just one item. We'll wire everything up to MongoDB because it doesn't make a lot of sense to have an API that doesn't have some data behind it, and then we'll allow the user to search for items using some query string parameters.

Posting DataThis is Jonathan Mills and in this module we're going to start talking about posting data into our API. Now so far we've worked on building out a RESTful API with Node and Express and we've implemented the Get verbs, which allows people to pull data from our API, but we're going to start talking about the Post verb in this module where we're going to let them add new items to our list through the HTTP Post verb. We're going to test everything with Postman, which is a Chrome extension that allows us to replicate all of the different HTTP verbs and not just the get, which is what we've been able to do so far in the browser, and by the time we're done with this our app. js file is going to be kind of unruly, so we're going to start talking about how to clean that up and segregate different pieces of our application into different files.

Updating DataThis is Jonathan Mills and in this module we're going to talk about updating data in our API. We've been following along building out a RESTful API using Node and Express and in this module we're going to implement the HTTP Put and Patch verbs that allow a user to update individual items. In Puts case we'll replace an existing item and in Patch's case we're going to update a specific part of an item. As part of that we'll also start to talk about Middleware. We've seen Middleware in use, but this time we're going to actually start to create our own route Middleware.

TestingI'm Jon Mills and in this module we're going to talk about testing and I know everybody tests differently and everybody prefers different things, so we're going to take a couple of different approaches to testing, so that you can understand a couple different ways to do it, and then take a pick as to the way that works best for you and your application. As a start we've built out a RESTful API with all of the HTTP verbs necessary, we haven't yet talked about hyper media, but we will get to that in our next module. For right now we're going to talk about unit testing to start with with Mocha and as part of unit testing the first thing we need to do is separate out our code, so that we have something that we can wrap in a test, so we're going to build out controllers for our routes, and then we're going to mock out our response objects with Sinon, so that we can then unit test our controllers. After that we're going to talk about integration tests and as part of that we'll use something called Supertest that's going to allow us to execute our HTTP calls and carry that all the way through to our database, so we can do our posts and our gets and test everything end to end in a testing framework.

HATEOASI'm Jon Mills and in this module we're going to be talking about HATEOAS or Hypertext as the Engine of Application State. We've been working through this process of building out a RESTful API with Node and Express. We've built all the verbs, we've got a book API going, we spend last module talking about testing and integration tests versus unit tests, and how all that works. There's one more constraint that I want to talk about today and that's HATEOAS and how using a hypermedia in our application helps to build this self documenting API that becomes very easy for someone to navigate and understand what options are available to them at any time while they're using your API.