https://users-app-assessment-backend-cl.onrender.com
Resource | Method | Route | Description |
---|---|---|---|
app | ALL | * | Error message |
app | GET | / | Healthcheck route |
users | GET | /users | Get all users |
users | GET | /users/{id} | Return one user by their id of {id} |
- What is the difference between
float
,double
, anddecimal
data types for latitude and longitude in SQL?
Example:
"latitude": 19.605271,
"longitude": -106.281246
In this challenge, you will take an Express API that serves hard-coded data from a JSON file and:
- deploy this API to render
- create a database for the API on ElephantSQL
- create a
users
table in your database - seed the table with the data from
usersData.json
- refactor the controllers and queries to serve data from your db
- deploy your changes so that your API on render calls the db
See the Detailed instructions section below for detailed instructions, tips, and hints.
- Fork this repo.
- Clone your fork to your computer.
- Install dependencies:
npm install
- Start the server:
npm start
- As you write code, push or merge it to the main branch of your fork (not the upstream repo)
- When the instructions, videos, or other resources say to make a PR, make that PR to your fork
- At the end of class, make a PR of your main branch to the upstream repo main branch (so I can review your code)
Deploying the API to render
Creating the DB and connecting API to DB
Create and seed data; serve data from DB
Reference code
After each stage of the challenge, make sure that all of these routes function as expected.
/
: returns a200
response: `{ data: 'Service is running' }/users
: returns a200
response in this format:{ data: [ {//user 1...}, { // user 2, ...}, ...]}
/users/:id
: returns a200
response in this format:{ data: { name: ..., age: ..., }}
/users/:id
: returns a404
response if the id does not exist:{ error: 'User with id ... not found'}
- Deploy your API to render.
- Make sure that all routes work.
- Paste your deployed URL in the top of this README.
- Commit and merge your changes to the main branch of your fork.
- Create a database on Elephant SQL
- Do not commit the connection string / URL to GitHub
- Create a
schema.sql
file in this repo that defines the table. The columns should match the keys and data types you see in theusersData.json
file. - Run the schema file to create the table in your db.
- Commit and merge your changes to the main branch of your fork.
The data type for
latitude
andlongitude
isfloat
.
- Create a
seeds.sql
file in this repo that adds at least 3 students fromusersData.json
to theusers
table. - The uuids in the table do not need to match the uuids in
usersData.json
(although it is possible to insert the exact ids from the JSON). - Commit and merge your changes to the main branch of your fork.
Don't waste time copy-pasting every single user from the JSON file. Just do 3 to start. Do the rest if you have time at the end.
The
about
texts have apostrophes. (For example:'Hi there! I'm Park...'
). These will cause problems because SQL statments require single quotes around strings.You can escape a single quote in a SQL statement by repeating it:
'Hi there! I''m Park...'
- Refactor the queries and controllers to fetch from the database.
- You will need to use
pg-promise
. It is already installed. - Use environment variables to store the connection string (database URL).
- Delete the
usersData.json
file. - Commit and merge your changes to the main branch of your fork.
- If it works locally, update your environment variables on Render, then push, merge, and deploy your code changes.
- By the end of this step, your deployed database should serve data from the db.