Today we will be building a server that will serve up data from the Ice and Fire API. We will be using the Express framework to build our server.
To conquer this challenge, complete the tasks listed below.
Run your server with npm run server
. Use Postman to test your routes.
- Fork and clone this repository
- Install dependencies with
npm install
- Review the resources listed in the Ice and Fire API documentation
- Download Postman to test your routes
- Require
express
- Create an
express
app - Create a server with
app.listen()
- Create a GET route for
/
that sends a response ofHello World!
- Test your server with
npm run server
and visitinglocalhost:3000
- Create a route for
/characters
that returns a list of 20 GOT characters - Create a route for
/character/name/:name
that returns a single character by name - Create a route for
/character/titles/:name
that returns a list of titles for a single character - Create a route for
/characters/:page
that returns a list of characters based on a page number - 🌶️ Refactor the
/characters/:page
controller function to use a query to return a specific number of characters per page. Use Ice and Fire API documentation.
- Create a route for
/character/books/:name
that returns a list of book titles for a single character - Create a route for
/character/allegiances/:name
that returns a list of character names for a single character's allegiances - Create a route for
/lords
that returns a list of all current lords for houses in the GOT universe.
-
Build a custom
errorHandler
function in theerrorMiddleware.js
file that responds with the error status and error message if an error occurs inside thecatch
block of the characterControllers_Hint:_ You can use `console.log(err)` to see what the error object looks like _Hint:_ Read documentation for the `next()` method in Express
-
Check if your error handler works by commenting out a controller function's code, adding
throw new Error('Error hit')
and running the route inPostman
- Build a custom
invalidPathHandler
function in theerrorMiddleware.js
file that returns a status of404
and an "Invalid path" message if a user attempts to use a url path that is not a route.