Our repo link. Our heroku link.
Week 7 REST API project
Explore the docs »
·
Report Bug
·
Request Feature
This is a project created as part of the Founders and Coders curriculum, week 7. The task was to build a REST API which returns JSON data. The project requirements.
- As an API user, I want to: get a list of all available resources
- As an API user, I want to: get all the information on a specific resource
- As an API user, I want to: create a new resource
- As an API user, I want to: update an existing resource
- As an API user, I want to: delete an existing resource
- As an API user, I want to: only be able to change an existing resource if I am authenticated to do so
Since this project is open-ended you'll need to write your own more specific user stories once you know what you want to build.
- An Express server that only returns JSON
- A Postgres database to store the data
- Endpoints for creating, reading, updating & deleting resources
- Token-based authentication so only the owner of a resource can change it
- Correct headers and response metadata
- Error-handling to make it easy to use the API to build something
- Tests for server routes and database access (server routes tests outstanding)
- Not process user input as SQL commands
- Hidden environment variables (i.e. not on GitHub)
- GitHub Actions CI setup to run your tests when you push
- Able to get a random fact
Our API is hosted on Heroku. Should you wish to get a local copy up and running, follow the simple steps below in Installation.
- Clone the repo
git clone https://github.com/fac20/week-7-BFOP.git
- Install NPM packages
npm install
- Create a database and a test database
CREATE DATABASE test_bfop;
CREATE DATABASE bfop;
\connect bfop
\include database/init.sql
- Create a .env file
- ensure this file is in your root folder
- it should contain 3 variables:
DATABASE_URL=postgres://youruser:yourpassword@localhost:5432/bfop
TEST_DATABASE_URL=postgres://youruser:yourpassword@localhost:5432/test_bfop
SECRET=randomstring
- create a user (automatically signed in)
- login
- create a post
- read a post by ID
- read all facts
- get all facts about a person
- update a fact you've written
- delete a fact you've written
- create a user (automatically signed in)
/signup
&&POST
{
"username": "<NAME>",
"password": "<PASSWORD>",
"cohort": "<FACXX>" (only 5 characters allowed)
}
- login
/login
&&POST
{
"username": "<NAME>",
"password": "<PASSWORD>"
}
(For the actions below, ensure you have a bearer token from either steps 1 OR 2)
3. create a fact /facts/
&& POST
{
"text_content": "<FACT>",
"about_who": "<WHO IS IT ABOUT>"
}
- read a fact by ID
/facts/:id
&&GET
- read all facts
/facts
&&GET
- get all facts about a person
/facts/name/:name
&&GET
- update a fact you've written
/facts/:id
&&PUT
{
"text_content": "<FACT>"
}
- delete a fact you've written
/facts/:id
&&DELETE
-
Get all cohort facts from the collection: curl --request GET
--url https://fun-facs-api.herokuapp.com/facts/ -
Sign up to add your own facts curl --request POST
--url https://fun-facs-api.herokuapp.com/signup
--header 'content-type: application/json'
--data '{ "username": "YOU", "password": "PICK_ONE", "cohort": "FAC20" }' -
Add a fact - you'll need your id and authorization token from the signin or login response curl --request POST
--url https://fun-facs-api.herokuapp.com/facts/
--header 'authorization: Bearer YOUR_TOKEN_HERE'
--header 'content-type: application/json'
--data '{ "owner_id": YOUR_ID_NUMBER, "about_who": "COHORT_MEMBER", "text_content": "FACT" }' -
Edit your fact - you can only edit facts you've added curl --request PUT
--url https://fun-facs-api.herokuapp.com/facts/FACT_ID_NUMBER
--header 'authorization: Bearer YOUR_TOKEN_HERE'
--header 'content-type: application/json'
--data '{ "about_who": "NEW_COHORT_MEMBER", "text_content": "NEW_TEXT" }' -
Delete your fact - you can only delete facts you've added curl --request DELETE
--url https://fun-facs-api.herokuapp.com/facts/FACT_ID_NUMBER
--header 'authorization: Bearer YOUR_TOKEN_HERE'
- Azizi - Scrum Facilitator,
- Lisa - Design,
- Terrence - Deployment,
- Aishah - Quality
- All of our past workshops