This is the API for the LeetRun client.
Complete the following steps to run the API locally:
- Clone this repository to your local machine
git clone LEETRUN-API_URL LEETRUN-API cdinto the cloned repository- Make a fresh start of the git history for this project with
rm -rf .git && git init - Install the node dependencies
npm install - Move the example Environment file to
.envthat will be ignored by git and read by the express servermv example.env .envand add your own values - Provision a PostgreSQL DB
- Run
npm run migrate - Seed the DB tables
psql -U your_user_name -d your_db_name -f ./seeds/seed.leetrun_tables.sql
Start the application npm start
Start nodemon for the application npm run dev
Run the tests npm test
When your new project is ready for deployment, add a new Heroku application with heroku create. This will make a new git remote called "heroku" and you can then npm run deploy which will push to this remote's master branch.
You will need to provision a PostgreSQL database on Heroku. All environmental variables above will need to set up in your Heroku config (e.g., heroku config:set var=value), along with the following variable: PGSSLMODE=no-verify.
- Run
npm run migrate:production - Get your credentials
heroku pg:credentials:url - Connect to your Heroku database (
heroku pg:psql) - Run
\i ./seeds/seed.leetrun_tables.sql
- Method:
GET
- URL Params:
api/runs/:run_entry_id
-
Success Response:
Code: 200
Content:[ { id: 1, user_name: "test-user-1", first_name: "Test 1", last_name: "User 1", password: "password", date_created: new Date("2029-01-22T16:28:32.615Z"), }, { id: 2, user_name: "test-user-2", first_name: "Test 2", last_name: "User 2", password: "password", date_created: new Date("2029-01-22T16:28:32.615Z"), }, ] -
Error Response:
Code: 404 NOT FOUND
Content:{ error:Run entry does not exist}
-
Method:
POST
- URL Params:
None
-
Success Response:
Code: 201
Content:{ id: 1, user_name: "test-user-1", first_name: "Test 1", last_name: "User 1", password: "password", date_created: new Date("2029-01-22T16:28:32.615Z"), } -
Error Response:
Code: 401 UNAUTHORIZED
Content:{"error":"Required properties are missing: [fields]{ error: "Invalid property values provided: [field]" }
- Method:
PATCH
- URL Params:
/api/runs/:run_entry_id
-
Success Response:
Code: 204
-
Error Response:
Code: 404 NOT FOUND
Content:{ error:Run entry does not exist}
- Method:
DELETE
- URL Params:
/api/runs/:run_entry_id
-
Success Response:
Code: 204
-
Error Response:
Code: 404 NOT FOUND
Content:{ error:Run entry does not exist}
- Method:
POST
- URL Params:
None
-
Success Response:
Code: 200
Content:{"authToken":"some.jwt.token"} -
Error Response:
Code: 400 BAD REQUEST
Content:{ error: "Incorrect user_name or password" }{ error: "Missing '${field}' in request body" }
- Method:
POST
- URL Params:
None
-
Success Response:
Code: 200
Content:{"authToken":"some.jwt.token"}
- Method:
POST
- URL Params:
None
-
Success Response:
Code: 201
Content:{ id: 1, first_name: "First", last_name: "Last", user_name: "Runner", date_created: "2021-02-19T02:21:18.434Z", } -
Error Response:
Code: 400 BAD REQUEST
Content:{ error: "Username already taken" }{ error: "Password must be longer than 8 characters" }{ error: "Password must be less than 72 characters" }{ error: "Password must not start or end with empty spaces" }{ error: "Password must contain one upper case, lower case, number and special character" }