Table of Contents
REST APIs with Express
Introduction
00:00:00 - 00:07:38
Introduction
Welcome to the course! Scott's background is in working on Tipe, OneSpeed, Angular and more. Scott gives an introduction to what Node.js is, a platform built on Chrome's V8 engine with it's own modules for HTTP and file I/O. He gives an overview of the popular Node.js frameworks.
Intro to Express
00:07:39 - 00:11:30
Intro to Express
Express is the most popular framework for building APIs and is very extensible. There are modules for routing, middleware, and lots of plugins to do whatever you would need for building APIs for REST and GraphQL. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-1Exercise: Setup Express
00:11:31 - 00:14:26
Exercise: Setup Express
Overview of the files involved in the exercise to bootstrap express.
Solution: Setup Express
00:14:27 - 00:17:49
Solution: Setup Express
Scott codes setting up express and returning a JSON response with a GET request. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-1Solution Branch Walkthrough
00:17:50 - 00:26:42
Solution Branch Walkthrough
Scott walks through the solution branch code which contains hot module reloading (HMR). HMR speeds up development by loading your node modules through webpack right after your files are saved. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-1-solutionRouting & Middleware
Routing with Express
00:26:43 - 00:42:06
Routing with Express
Express Routing module has many features including pattern matching, multi-router support and support for all HTTP verbs.
Excercise: Express Routing
00:42:07 - 00:49:40
Excercise: Express Routing
In the challenge you'll be creating your own express sub router modules to route different paths to resources in the API. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-2Solution: Express Routing
00:49:41 - 01:02:34
Solution: Express Routing
Scott walks through the solution of importing the sub routers and setting up the routes. He takes the parameter of the route and passes that to the controllers. Scott also gives an overview of REST using HTTP verbs and the tradeoffs of it. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-2-solutionControllers & Responding
01:02:35 - 01:14:45
Controllers & Responding
Inside controllers you handle incoming requests and send back the response. Scott codes a controller method that works for all the resources as well as handles errors.
Exercise: Controllers & Responding
01:14:46 - 01:16:21
Exercise: Controllers & Responding
Scott sets up the next exercise for getting the API route tests to pass by implementing the controller methods. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-3Solution: Controllers & Responding
01:16:22 - 01:29:25
Solution: Controllers & Responding
Review of the solution implimneting the methods to create, update and read the model data based on the routes. Scott also reviews how the route parameter gets passed into the param method in the router. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-3-solutionMiddleware
01:29:26 - 01:35:27
Middleware
Middleware allows you add hooks to run a set of functions before the request is send to the controller. This is great for adding behaviors like authentication and logging to your express API.
Exercise: Middleware
01:35:28 - 01:44:14
Exercise: Middleware
Scott sets up the middleware challenge. Scott get you started JSON parsing with the bodyParser middleware. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-4Solution: Middleware
01:44:15 - 01:53:56
Solution: Middleware
Review of the middleware solution to parse the URL and protect the API with authentication middleware.
MongoDB
MongoDB Introduction
01:53:57 - 01:57:49
MongoDB Introduction
Overview of the MongoDB is database that stores JSON with a query language built in JavaScript.
Setup Mongo Models with Mongoose
01:57:50 - 02:06:00
Setup Mongo Models with Mongoose
Scott shows how to get up and running with MongoDB by creating Mongo models using schemas with the Mongoose node library.
Exercise: MongoDB Models
02:06:01 - 02:11:21
Exercise: MongoDB Models
Create MongoDB models with schemas to pass the tests. Scott covers how to throw custom model data errors and get started with the exercise. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-5Solution: MongoDB Models
02:11:22 - 02:16:07
Solution: MongoDB Models
Scott walks through building out the model schemas in Mongoose. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-5-solutionCRUD in the Controllers
02:16:08 - 02:18:19
CRUD in the Controllers
Create controller methods to handle each of the CRUD (Create, Read, Updated & Delete) verbs.
Challenge: Querying MongoDB
02:18:20 - 02:30:10
Challenge: Querying MongoDB
Learn how to query MongoDB. In this exercise you need to code find by ID, find by name, create and update. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-6Solution: Querying MongoDB
02:30:11 - 02:35:00
Solution: Querying MongoDB
Learn how to query MongoDB. Scott shows how to find by ID, find by name, create and update documents and more. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-6-solutionConfig & Tests
Dynamic Configuration
02:35:01 - 02:45:14
Dynamic Configuration
Make your configuration files dynamic by having a base configuration and injecting variables into each environment based on the environment variables.
Exercise: Dynamic Config
02:45:15 - 02:51:36
Exercise: Dynamic Config
Create an extendable configuration file based on the development environment. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-7Solution: Dynamic Config
02:51:37 - 02:58:58
Solution: Dynamic Config
Change your configuration: secrets, keys, and URLs based on your environment. Scott also shows how you can create environment files to store your secrets. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-7-solutionWriting Tests
02:58:59 - 03:05:34
Writing Tests
How to code out unit tests using mocha and chai. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-8GraphQL
GraphQL Overview
03:05:35 - 03:12:48
GraphQL Overview
An introduction to GraphQL, a query language for your API that allows the client to describe how they want their data.
GraphQL vs REST
03:12:49 - 03:16:54
GraphQL vs REST
A comparison of REST and GraphQL. GraphQL is typed and is a dynamic single endpoint. With REST you have to predefine the data and endpoints individually
GraphQL Schemas
03:16:55 - 03:21:35
GraphQL Schemas
GraphQL APIs use schemas to definte the types, queries and mutations that can be queried on the API endpoint.
Queries and Mutations Walkthrough
03:21:36 - 03:36:32
Queries and Mutations Walkthrough
Scott walks through GraphQL queries and mutations using the interactive documentation that comes with GraphQL called "GraphiQL".
Exercise: GraphQL Schemas
03:36:33 - 03:42:16
Exercise: GraphQL Schemas
Create the type definitions for Song and Playlist. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-9Solution: GraphQL Schemas
03:42:17 - 04:00:43
Solution: GraphQL Schemas
Scott walks you through how to create the type definitions for Song and Playlist. He also answers questions about using comments in GraphQL and auto-generating schemas. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-9-solutionGraphQL & Express
04:00:44 - 04:03:43
GraphQL & Express
GraphQL is seprate from the server and request-response cycle. So you need a server like Express to send and receive the data for your API. Express talks to the Node libraries that impliment GraphQL.
Exercise: GraphQL & Express
04:03:44 - 04:13:48
Exercise: GraphQL & Express
Get started with using the Express Apollo extension to attach GraphQL to the Express server. Scott walks through the setup code. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-10Solution: GraphQL & Express
04:13:49 - 04:25:45
Solution: GraphQL & Express
Scott walks you through gettings setup with resolving GraphQL requests through the Express Apollo server module. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-10-solutionGraphQL Resolvers
Resolvers Overview
04:25:46 - 04:36:56
Resolvers Overview
Resolvers allow you to define queries. Resolver methods take four parameters: root value, arguments, context and the AST of the query. You'll most of the time just use arguments and context.
Nested Resolvers
04:36:57 - 04:42:45
Nested Resolvers
The magic graphQL is in being able to nest resolvers and continue to resolve more data into the response as the user requests more data in the GraphQL query. You can avoid resolvers from running altogether if the user doesn't need that data that the resolver provides.
Exercise: Resolvers
04:42:46 - 04:48:30
Exercise: Resolvers
Create the resolvers for the Song type and Playlist type. Use the User type example for reference. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-11Solution: Resolvers
04:48:31 - 05:03:57
Solution: Resolvers
Coding out the Song resolvers and how to handle errors in GraphQL Apollo Server. Scott also shows where nested resolvers are needed. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-11-solutionGraphQL Mutations
Mutations Overview
05:03:58 - 05:10:02
Mutations Overview
When you need to make changes to the data source you can add a mutation. Mutations need their own resolvers.
Mutations Walkthrough
05:10:03 - 05:21:18
Mutations Walkthrough
Scott walks through how to use a mutation from the client in the query and how to impliment that mutation on the server.
Exercise: Mutations
05:21:19 - 05:23:42
Exercise: Mutations
Impliment the create, update and remove mutations for Song and Playlist models. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-12Solution: Mutations
05:23:43 - 05:43:15
Solution: Mutations
Walkthrough of coding the create, update and remove mutations for the Song and Playlist model. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-12-solutionsNested Resolvers
Non Scalars
05:43:16 - 05:48:02
Non Scalars
Any custom type or object in GraphQL is a non scalar. Non scalars have to be resolved to primitive types.
Exercise: Non Scalars
05:48:03 - 05:58:20
Exercise: Non Scalars
Code nested resolvers for resolving the non scalar type references in your models. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-13Solution: Non Scalars
05:58:21 - 06:13:10
Solution: Non Scalars
Scott codes nested resolvers to resolve the non scalar types. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-13-solutionTracing Nested Resolvers
06:13:11 - 06:16:48
Tracing Nested Resolvers
Demonstration of logging the resolver methods to show which resolvers are run depending on the query on the client. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-13-solutionAuthentication
06:16:49 - 06:21:26
Authentication
Protect your data using authentication on all of your resolvers.
Exercise: Testing
06:21:27 - 06:29:07
Exercise: Testing
In this challenge you are to write out tests for the GraphQL model mutations and resolvers. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-14Solution: Testing
06:29:08 - 06:35:31
Solution: Testing
Scott codes out tests for a GraphQL mutation and resolver. -
https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-14-solutionFinal
Using REST & GraphQL
06:35:32 - 06:40:27
Using REST & GraphQL
There are many different strategies to exposing and using both REST and GraphQL APIs on the same API.
Q&A and Wrap-up
06:40:28 - 06:45:44
Q&A and Wrap-up
Scott wraps up with Q&A about GraphQL. Scott says he uses Apollo GraphQL server for everything. He believes Graph APIs will replace REST entirely since it's a much better fit for the types of applications we build today. Follow him on twitter @scotups -
https://twitter.com/scotups