- Github: github.com/nicorithner
- LinkedIn: linkedin.com/in/nicorithner/
- E-mail: [email protected]
Create a REST API using Node.js and PostgreSQL. Seed the database from the data provided as JSON and expose REST APIs with some specific filtering requirements.
-
REST API using Node / Express API with PostgreSQL Database
-
README with clear instructions on how to run and use the application
-
Seed script that seeds the PostgreSQL Database with the provided data
-
CRUD APIs for each entity
-
GET Shows and filter by Network (ex: /shows?network_id=1)
-
GET Shows and filter by Package (ex: /shows?package_id=1)
-
GET Package by ID should also provide all Networks included in that Package (ex: /packages/:id)
- NodeJS
- ExpressJS
- PostgreSQL
- Sequelize
The project includes three main tables and a through-table.
Based on the data provided as json:
- A 'package' has many networks.
- A 'network' belongs to many packages.
- A 'network' has mnay shows.
- A 'show' belongs to a network.
To avoid nesting packages and network are associated through a join table named 'packageNetworks'. A 'packageNetworks' table has both a package and a network foreign key. A 'show' belongs to a newtork only so there is a reference to network in 'show' with a foreing key.
- Make sure you have yarn installed
- Clone this repo
git clone [email protected]:Coding-Gymnasium/node-express-api-2023.git
- Cd to project and run
yarn install
- Set psql user:
$ psql <default-user>=# CREATE USER postgres WITH PASSWORD "postgres"; <default-user>=# GRANT ALL PRIVILEGES ON DATABASE node_express_api_dev TO postgres;
- Create database
npx sequelize-cli db:create
- Migrate tables
yarn migrate:up
- Seed tables. Note: because of the associations the tables need to be seed in order. Please use the following command:
yarn seed-in-order
- Run project
yarn start
POST ➡️ http://localhost:8000/api/v1/packages/
{
"name": "Gold"
}
GET ➡️ http://localhost:8000/api/v1/packages/
GET ➡️ http://localhost:8000/api/v1/packages/1
- Displays Networks associated with package
PUT ➡️ http://localhost:8000/api/v1/packages/1
Change price
{
"price": 19.9
}
DELETE ➡️ http://localhost:8000/api/v1/packages/1
DELETE ➡️ http://localhost:8000/api/v1/packages
POST ➡️ http://localhost:8000/api/v1/networks/
{
"name": "ABC"
}
GET ➡️ http://localhost:8000/api/v1/networks/
GET ➡️ http://localhost:8000/api/v1/networks/1
PUT ➡️ http://localhost:8000/api/v1/networks/1
Change name
{
"name": "CBS"
}
DELETE ➡️ http://localhost:8000/api/v1/networks/1
DELETE ➡️ http://localhost:8000/api/v1/networks
POST ➡️ http://localhost:8000/api/v1/shows/
{
"title": "American Gods",
"imdb_rating": 7.7
}
GET ➡️ http://localhost:8000/api/v1/shows/
GET ➡️ http://localhost:8000/api/v1/shows?package_id=1
GET ➡️ http://localhost:8000/api/v1/shows?network_id=2
GET ➡️ http://localhost:8000/api/v1/shows/1
PUT ➡️ http://localhost:8000/api/v1/shows/1
Change title
{
"title": "Forge in Fire"
}
Change network
{
"NetworkId": 2
}
DELETE ➡️ http://localhost:8000/api/v1/shows/1
DELETE ➡️ http://localhost:8000/api/v1/shows
POST ➡️ http://localhost:8000/api/v1/packageNetworks/
{
"NetworkId": 1,
"PackageId": 2
}
GET ➡️ http://localhost:8000/api/v1/packageNetworks/
GET ➡️ http://localhost:8000/api/v1/packageNetworks/1
PUT ➡️ http://localhost:8000/api/v1/packageNetworks/1
{
"id": 4
}
DELETE ➡️ http://localhost:8000/api/v1/packageNetworks/1
DELETE ➡️ http://localhost:8000/api/v1/packageNetworks
To use the swagger ui please navigate to:
http://localhost:8000/api-docs