CREATE DATABASE gamestore
or createdb gamestore
npm install
npn run seed
In this workshop, you will learn how to create a RESTful API with Express using try / catch blocks. We'll also review body-parser and how to use it to parse the body of a request as well as CORS middleware.
Inside our /api/
directory, we have a videoGames.js
file. This file contains all of our video game routes. We have already created the route handler for GET /api/video-games
. This route handler will return all of the video games in our database.
HINT: Follow the logic in the getAllVideoGames()
function.
Our GET /api/video-games/:id
route handler is not working. We need to fix this route handler so that it returns a single video game by ID.
Write the route handler and database query for POST /api/video-games
. This route handler should add a new video game to the database.
HINT: Follow the logic in the createVideoGame()
function.
Write the route handler and database query for PUT /api/video-games/:id
. This route handler should update a video game in the database.
Write the route handler and database query for DELETE /api/video-games/:id
. This route handler should delete a video game from the database.
Port 8080 by default.
Method | Endpoint | Description |
---|---|---|
GET | / | Returns a welcome message |
GET | /api/health | Returns a health check message |
GET | /api/video-games | Returns all video games |
GET | /api/video-games/:id | Returns a single video game by ID |
POST | /api/video-games | Adds a new video game |
PUT | /api/video-games/:id | Updates a video game |
DELETE | /api/video-games/:id | Deletes a video game |
GET | /api/board-games | Returns all board games |
GET | /api/board-games/:id | Returns a single board game by ID |
POST | /api/board-games | Adds a new board game |
PUT | /api/board-games/:id | Updates a board game |
DELETE | /api/board-games/:id | Deletes a board game |