- Describe the concept of resources in relation to REST and APIs
- Identify RESTful conventions for API routes
- Explain what express is and why it's useful
- Build RESTful routes using express
-
What is a resource?
Your answer...
-
What are the five common actions of an API? What methods and status codes are typically used for the five common actions?
Your answer...
-
Build RESTful routes for one of the following resources: cards, dogs, engineers
Action Method Path Body _ _ _ _ _ Your answer...
-
Attept this REST Quiz!
-
How would you build RESTful routes for the following data?
const authors = [ { name: 'Haruki Murakami', books: [ { title: 'Hard-Boiled Wonderland and the End of the World' }, { title: 'The Wind-Up Bird Chronicle' } ] }, { name: 'Kurt Vonnegut' books: [ { title: 'Slaughterhouse-Five' } ] } ]
- Get all authors
- Get one author
- Add new author
- Get all books by author
- Get one book by author
- Add new book by author
- Edit one book by author
- Delete one book by author
- Challenge: Get a specific number of authors?
Your answer...
-
Given the following examples of a web server written with Node http and Express that perform the same tasks
const fs = require('fs') const http = require('http') const server = http.createServer(function(request, response) { if(request.url === '/logo.png') { response.writeHead(200, {'Content-Type': 'image/gif'}) fs.readFile(__dirname + '/public/logo.png', function(err, data) { if(err) console.log(err) response.end(data) }) } else if (request.url === '/'){ response.writeHead(200, {'Content-Type': 'text/html' }) fs.readFile(__dirname + '/public/index.html', function(err, data) { if(err) console.log(err) response.end(data) }) } }) // and much more besides
const express = require('express') const http = require('http') const app = express() app.use(express.static('./public')) app.get('/', function(req, res, next) { res.sendFile('./public/index.html') }) http.createServer(app).listen(3000) console.log('Express server is listening on port 3000')
-
What are the tasks performed?
-
What parts are of the process does Express help you with