Giter VIP home page Giter VIP logo

users-app-assessment-backend's Introduction

Backend deployment and database challenge

My deployed API URL is:

https://users-app-assessment-backend-cl.onrender.com

Endpoints:

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}

Questions:

  1. What is the difference between float, double, and decimal data types for latitude and longitude in SQL?

Example:

"latitude": 19.605271,
"longitude": -106.281246

Overview

In this challenge, you will take an Express API that serves hard-coded data from a JSON file and:

  1. deploy this API to render
  2. create a database for the API on ElephantSQL
  3. create a users table in your database
  4. seed the table with the data from usersData.json
  5. refactor the controllers and queries to serve data from your db
  6. deploy your changes so that your API on render calls the db

See the Detailed instructions section below for detailed instructions, tips, and hints.

Getting started

  1. Fork this repo.
  2. Clone your fork to your computer.
  3. Install dependencies: npm install
  4. Start the server: npm start

Submitting

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

Helpful resources

Deploying the API to render

Creating the DB and connecting API to DB

Create and seed data; serve data from DB

Reference code

Routes

After each stage of the challenge, make sure that all of these routes function as expected.

  • /: returns a 200 response: `{ data: 'Service is running' }
  • /users: returns a 200 response in this format: { data: [ {//user 1...}, { // user 2, ...}, ...]}
  • /users/:id: returns a 200 response in this format: { data: { name: ..., age: ..., }}
  • /users/:id: returns a 404 response if the id does not exist: { error: 'User with id ... not found'}

Detailed instructions

1. Deploy to render

  1. Deploy your API to render.
  2. Make sure that all routes work.
  3. Paste your deployed URL in the top of this README.
  4. Commit and merge your changes to the main branch of your fork.

2. Create a database

  1. Create a database on Elephant SQL
  2. Do not commit the connection string / URL to GitHub

3. Create the users table

  1. Create a schema.sql file in this repo that defines the table. The columns should match the keys and data types you see in the usersData.json file.
  2. Run the schema file to create the table in your db.
  3. Commit and merge your changes to the main branch of your fork.

Tips and hints

The data type for latitude and longitude is float.

4. Seed the table with the data from usersData.json

  1. Create a seeds.sql file in this repo that adds at least 3 students from usersData.json to the users table.
  2. 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).
  3. Commit and merge your changes to the main branch of your fork.

Tips and hints

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

5. Serve data from the db

  1. Refactor the queries and controllers to fetch from the database.
  2. You will need to use pg-promise. It is already installed.
  3. Use environment variables to store the connection string (database URL).
  4. Delete the usersData.json file.
  5. Commit and merge your changes to the main branch of your fork.

6. Final deployment

  1. If it works locally, update your environment variables on Render, then push, merge, and deploy your code changes.
  2. By the end of this step, your deployed database should serve data from the db.

users-app-assessment-backend's People

Contributors

christina-ml avatar mikeboyle avatar

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.