Skip to content

REST API that returns JSON data. Endpoints built for creating, reading, updating and deleting data. Week 7 REST API project.

Notifications You must be signed in to change notification settings

fac20/week-7-BFOP

Repository files navigation

Our repo link. Our heroku link.

Fun FACs

Week 7 REST API project
Explore the docs »
· Report Bug · Request Feature

Table of Contents

About The Project

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.

User stories

  • 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.

Acceptance Criteria

  • 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)

Stretch criteria

  • GitHub Actions CI setup to run your tests when you push
  • Able to get a random fact

Getting Started

Our API is hosted on Heroku. Should you wish to get a local copy up and running, follow the simple steps below in Installation.

Installation

  1. Clone the repo
git clone https://github.com/fac20/week-7-BFOP.git
  1. Install NPM packages
npm install
  1. Create a database and a test database
  • CREATE DATABASE test_bfop;
  • CREATE DATABASE bfop;
  • \connect bfop
  • \include database/init.sql
  1. 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

Usage Instructions

What you can do:

  • 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

Our table schema

schema week 7

To use the API locally/using Insomnia/Postman: (Replace values within <>)

  1. create a user (automatically signed in) /signup && POST
{
	"username": "<NAME>",
	"password": "<PASSWORD>",
	"cohort": "<FACXX>" (only 5 characters allowed)
}
  1. 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>"
}
  1. read a fact by ID /facts/:id && GET
  2. read all facts /facts && GET
  3. get all facts about a person /facts/name/:name && GET
  4. update a fact you've written /facts/:id && PUT
{
	"text_content": "<FACT>"
}
  1. delete a fact you've written /facts/:id && DELETE

Here are some curls if you wish to test the Heroku version:

Team

  • Azizi - Scrum Facilitator,
  • Lisa - Design,
  • Terrence - Deployment,
  • Aishah - Quality

Acknowledgements

  • All of our past workshops

About

REST API that returns JSON data. Endpoints built for creating, reading, updating and deleting data. Week 7 REST API project.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •