Overview: This project was built in order to practice building a restful API, viewing it in Postgres, and accessing data on a local server and from the API deployed to Heroku.
Sprint Board: https://github.com/BrandyMello/byob/projects/1
- Clone/Fork and Clone https://github.com/BrandyMello/byob.git
cd byob
mkdir byob && cd byob
npm init --yes
npm install
npm i -g knex
$ psql
CREATE DATABASE byob;
\c byob
knex migrate:latest
knex seed:run
knex migrate:latest
node server.js
and open http://localhost:3000/
To GET all Countries:
GET /api/v1/countries
Return:
{
id: 2146,
name: "China",
created_at: "2019-10-04T22:12:10.136Z",
updated_at: "2019-10-04T22:12:10.136Z",
country_population: 1,
country_land_area: 9
},
{
id: 2147,
name: "United States",
created_at: "2019-10-04T22:12:10.152Z",
updated_at: "2019-10-04T22:12:10.152Z",
country_population: 329,
country_land_area: 9
},
{
id: 2155,
name: "Nigeria",
created_at: "2019-10-04T22:12:10.154Z",
updated_at: "2019-10-04T22:12:10.154Z",
country_population: 200,
country_land_area: 910
},...
]
To GET all Territories:
GET /api/v1/territories
Returns:
{
id: 1,
name: "Taiwan",
countryId: 2146,
created_at: "2019-10-04T22:12:10.287Z",
updated_at: "2019-10-04T22:12:10.287Z",
territory_population: 23,
population: null
},
{
id: 2,
name: "Hong Kong",
countryId: 2146,
created_at: "2019-10-04T22:12:10.292Z",
updated_at: "2019-10-04T22:12:10.292Z",
territory_population: 7,
population: null
},
{
id: 3,
name: "Réunion",
countryId: 2167,
created_at: "2019-10-04T22:12:10.295Z",
updated_at: "2019-10-04T22:12:10.295Z",
territory_population: 888,
population: null
},...
]
To GET a country by id:
GET /api/v1/countries/:id
example: api/v1/countries/2342
Returns:
{
id: 2342,
name: "TestLand",
created_at: "2019-10-06T14:12:23.427Z",
updated_at: "2019-10-06T14:12:23.427Z",
country_population: 4000,
country_land_area: 500000
}
]
To GET a territory by id:
GET /api/v1/territories/:id
example: /api/v1/territories/3
Returns:
{
id: 3,
name: "Réunion",
countryId: 2167,
created_at: "2019-10-04T22:12:10.295Z",
updated_at: "2019-10-04T22:12:10.295Z",
territory_population: 888,
population: null
}
]
To POST a country:
POST /api/v1/countries
Request Body:
{
"name": "TestLand",
"country_population": 4500,
"country_land_area": 550000
}
Returns:
{
"id": 2347
}
To POST a territory:
POST /api/v1/territories
Request Body:
{
"name": "TestTerritory",
"territory_population": 4500,
"territoryOf": "TestLand"
}
Returns:
NOT CURRENTLY FUNCTIONING
To DELETE a country:
DELETE /api/v1/countries/:id
example: DELETE /api/v1/countries/2349
Returns:
Country with the ID 2349 has been deleted.