Giter Club home page Giter Club logo

byob's Introduction

BYOB - Build Your Own Backend

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

Table of Contents

  1. Schema
  2. Setup
  3. API Endpoints

Screen Shot 2019-10-01 at 9 19 51 PM

Requirements: PostgreSQL, Node.js, and Express

Run

cd byob
mkdir byob && cd byob
npm init --yes
npm install
npm i -g knex
$ psql
CREATE DATABASE byob;
\c byob

Migration and Seeding Tables

knex migrate:latest
knex seed:run
knex migrate:latest

Run Server

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.

byob's People

Contributors

brandymello avatar

Watchers

James Cloos avatar  avatar

byob's Issues

Migration over rolled back and removed migration not working

I created a migration to correct an error I had in the prior migration. When attempting to deploy, I repeatedly got an error saying that the table already existed. I rolled back once. I could not migrate to the latest. Got an error saying that the rolled back migration failed. I removed the migration via command line. Still would not get passed the migration. Now my table has an additional unnecessary row and I am unable to post to that table.

POST for territory not working

Not sure if this has to do with the migration issue.
Difficult to test DELETE of territory when POST is not working.
-Want to include removing territory of country when county is deleted

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.