Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Prerequisites ™  Node and npm are installed ™  MongoDB is installed and running ™  Love APIs and Beer

Slide 3

Slide 3 text

Agenda ™  REST ™  Basic express application ™  Tooling ™  MongoDB, Mongoose and models ™  Create, read, update, & delete endpoints (CRUD) ™  Passport overview ™  Add User accounts ™  Build Auth controller ™  Lockdown CRUD endpoints

Slide 4

Slide 4 text

REST – Representational State Transfer ™  Style of architecture for web services. ™  De facto web service design model. ™  Displaced other design models such as SOAP and WSDL due to its simpler style.

Slide 5

Slide 5 text

RESTful Web Services A RESTful web service is a web service implemented using HTTP and the principles of REST. It is a collection of resources, with four defined aspects: ™  The base URI for the web service such as http://site.com/api ™  The content type of the data supported by the web service. This could be JSON, XML, or any other valid Internet media type ™  The set of operations supported by the web service such as GET, PUT, POST, or DELETE. ™  The API must be hypertext driven.

Slide 6

Slide 6 text

CRUD ™ Create POST/cars HTTP/1.1 ™ Read GET /cars HTTP/1.1 GET /cars/tesla HTTP/1.1 ™ Update PUT /cars/tesla HTTP/1.1 ™ Delete DELETE /cars/ford HTTP/1.1

Slide 7

Slide 7 text

Create the Server

Slide 8

Slide 8 text

Demo time

Slide 9

Slide 9 text

Tools ™  Nodemon ™  Postman

Slide 10

Slide 10 text

Nodemon ™  Monitors for changes in source code and automatically restarts your server

Slide 11

Slide 11 text

Postman ™  Postman is a powerful HTTP client to help test web services easily and efficiently. It lets you craft simple as well as complex HTTP requests quickly.

Slide 12

Slide 12 text

MongoDB and Mongoose ™  Load the Mongoose package ™  Connect to MongoDB using Mongoose ™  Create our Beer model

Slide 13

Slide 13 text

Demo time

Slide 14

Slide 14 text

Accept POST & PUT data ™  Load the body-parser middleware ™  Use the body-parser middleware

Slide 15

Slide 15 text

Add beer to our locker ™  Create a new Express route at /beers ™  Create a POST endpoint on new route ™  Create a Mongoose Beer model ™  Set Beer model data from POST request ™  Save the Beer model to MongoDB

Slide 16

Slide 16 text

Party time, get all the beer! ™  Create a GET endpoint on /beers route ™  Use the Mongoose Beer model to get all beer

Slide 17

Slide 17 text

Pace yourself with a beer ™  Create a new Express route at /beer/:beer_id ™  Create a GET endpoint on new route ™  Use the Mongoose Beer model to find the right beer

Slide 18

Slide 18 text

Updating beer quantity ™  Create a PUT endpoint on /beer/:beer_id route ™  Use the Mongoose Beer model to find the right beer ™  Use the Mongoose Beer model to update the right beer

Slide 19

Slide 19 text

I drank my last beer! ™  Create a DELETE endpoint on /beer/:beer_id route ™  Use the Mongoose Beer model to find the right beer ™  Use the Mongoose Beer model to remove the right beer

Slide 20

Slide 20 text

Passport Official description: “Authentication middleware for Node.js. Extremely flexible and modular, Passport can be unobtrusively dropped in to any Express-based web application. A comprehensive set of strategies support authentication using a username and password, Facebook, Twitter, and more.”

Slide 21

Slide 21 text

Passport Features ™  140+ authentication strategies ™  Single sign-on with OpenID and Oauth ™  Supports persistent sessions ™  Pick and choose required strategies ™  Create your own strategies

Slide 22

Slide 22 text

User Model and Controller ™  Create the User model ™  Create the User controller ™  Route to our User controller endpoints

Slide 23

Slide 23 text

Demo time

Slide 24

Slide 24 text

Auth Controller ™  Create and use the BasicStrategy passport strategy ™  Update routes to use authentication

Slide 25

Slide 25 text

Don’t touch my beer! ™  Update Beer model to define ownership ™  Update Beer controller to use ownership

Slide 26

Slide 26 text

No content