GithubHelp home page GithubHelp logo

lindsaywparker / byob Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 666 KB

"Build Your Own Backend" with US Rental Market statistics

JavaScript 98.70% HTML 0.77% CSS 0.53%
postgresql express knex jsonwebtoken chai mocha

byob's Introduction

Build Your Own Backend (BYOB) - A Turing Mod 4 FEE Project

Synopsis

This API follows CRUD design using the Zillow Zri data for rental markets in the United States, from the state level down to the local level at which point locations are separated by either neighborhood name or zipcode.

See It Live

BYOB on Heroku

Set Up

Clone the repo

Run npm install from the root directory

Run npm start and visit localhost:3000 in your browser

Test Driven Development

BYOB uses Mocha and Chai for testing

Run with npm test

Original Assignment

BYOB

Documentation

Region Types

  • state
  • metro
  • city
  • neighborhood
  • zipcode

Endpoints

GET /api/v1/:regionType
  • Description: Returns an array of all associated records for that table
  • Parameters
    • regionType: Region type to be retrieved (see list of region types above)
    • Query Parameters:
      • name
      • collected_on
      • median_rent
      • monthly_change
      • quarterly_change
      • yearly_change
      • size_rank
      • state (all except state table)
      • abbr (state table only)
      • metro (city, neighborhood, zipcode tables only)
      • county (city, neighborhood, zipcode tables only)
      • city (neighborhood, zipcode tables only)
  • Return Format: A JSON object
  • Errors
    • 404 Table Not Found: The region type provided does not exist, confirm intended path.
    • 500 Server Error: There was an error retrieving the requested records, try again.
  • Example
    • Request
    GET /api/v1/neighborhood?state=CA
    
    • Return
    [
        {
          "id": 59,
          "name": "Sherman Oaks",
          "metro_id": 77,
          "state_id": 970,
          "city_id": 200,
          "collected_on": "2017-06-30T06:00:00.000Z",
          "median_rent": 3610,
          "monthly_change": "0.00",
          "quarterly_change": "0.01",
          "yearly_change": "0.03",
          "size_rank": 4,
          "created_at": "2017-08-27T00:27:45.140Z",
          "updated_at": "2017-08-27T00:27:45.140Z",
          "state": "CA",
          "metro": "Los Angeles-Long Beach-Anaheim",
          "county": "Los Angeles",
          "city": "Los Angeles"
        },
        {
          "id": 61,
          "name": "Southeast Los Angeles",
          "metro_id": 77,
          "state_id": 970,
          "city_id": 200,
          "collected_on": "2017-06-30T06:00:00.000Z",
          "median_rent": 2314,
          "monthly_change": "0.01",
          "quarterly_change": "0.05",
          "yearly_change": "0.14",
          "size_rank": 10,
          "created_at": "2017-08-27T00:27:45.140Z",
          "updated_at": "2017-08-27T00:27:45.140Z",
          "state": "CA",
          "metro": "Los Angeles-Long Beach-Anaheim",
          "county": "Los Angeles",
          "city": "Los Angeles"
        }
    ]

POST /api/v1/:regionType
  • Description: Add a single location to the specified table
  • Parameters: Region type to modify (only neighborhood and zipcode currently available)
  • Request body must contain:
    • name
    • collected_on
    • median_rent
    • monthly_change
    • quarterly_change
    • yearly_change
    • size_rank
    • state (all except state table)
    • abbr (state table only)
    • metro (city, neighborhood, zipcode tables only)
    • county (city, neighborhood, zipcode tables only)
    • city (neighborhood, zipcode tables only)
  • Authorization
    • JWT with admin rights required
  • Return Format: A JSON object
  • Errors
    • 404 Table Not Found: The region type provided does not exist, confirm intended path.
    • 500 Server Error: There was an error modifying the requested records, try again.
    • 23502 Database error: Missing required parameters
    • Unacceptable POST target: Attempted to POST to a table outside of those allowed
    • You must be authorized to hit the endpoint: JSON web token was either not applied or invalid
  • Example
    • Request
    POST '/api/v1/:regionType'
    body: 
    {
        name: 'Ping pong',
        metro_id: 43,
        state_id: 767,
        city_id: 13,
        collected_on: '2017-06-30T06:00:00.000Z',
        median_rent: 1736,
        monthly_change: '0.00',
        quarterly_change: '0.00',
        yearly_change: '0.01',
        size_rank: 83,
        created_at: '2017-08-22T22:38:13.668Z',
        updated_at: '2017-08-22T22:38:13.668Z',
        state: 'TX',
        metro: 'Dallas-Fort Worth',
        county: 'Dallas',
        city: 'Dallas'
    }
    Authorization: 'some-valid-token'
    • Return
    {
    "result": [
        {
            "id": 10,
            "name": "Ping pong",
            "metro_id": 43,
            "state_id": 767,
            "city_id": 13,
            "collected_on": "2017-06-30T06:00:00.000Z",
            "median_rent": 1736,
            "monthly_change": "0.00",
            "quarterly_change": "0.00",
            "yearly_change": "0.01",
            "size_rank": 83,
            "created_at": "2017-08-22T22:38:13.668Z",
            "updated_at": "2017-08-22T22:38:13.668Z",
            "state": "TX",
            "metro": "Dallas-Fort Worth",
            "county": "Dallas",
            "city": "Dallas"
        }
      ]
    }

PUT /api/v1/:regionType
  • Description: Modify multiple records in the specified table
  • Parameters
    • regionType: Region type to modify
    • name: Required
    • collected_on
    • median_rent
    • monthly_change
    • quarterly_change
    • yearly_change
    • size_rank
    • state (all except state table)
    • abbr (state table only)
    • metro (city, neighborhood, zipcode tables only)
    • county (city, neighborhood, zipcode tables only)
    • city (neighborhood, zipcode tables only)
  • Return Format: A JSON object
  • Errors
    • 404 Table Not Found: The region type provided does not exist, confirm intended path.
    • 500 Server Error: There was an error modifying the requested records, try again.
  • Example
    • Request
    PUT /api/v1/neighborhood
    
    • Return
    {
        "results": [
          [
            {
              "id": 58,
              "name": "Upper East Side",
              "metro_id": 76,
              "state_id": 972,
              "city_id": 199,
              "collected_on": "2017-06-30T06:00:00.000Z",
              "median_rent": 3000,
              "monthly_change": "0.00",
              "quarterly_change": "0.00",
              "yearly_change": "-0.05",
              "size_rank": 6,
              "created_at": "2017-08-27T00:27:45.140Z",
              "updated_at": "2017-08-27T00:27:45.140Z",
              "state": "NY",
              "metro": "New York",
              "county": "New York",
              "city": "New York"
            }
          ],
          null,
          null,
          null,
          null,
          null,
          null,
          [
            {
              "id": 57,
              "name": "Upper West Side",
              "metro_id": 76,
              "state_id": 972,
              "city_id": 199,
              "collected_on": "2017-06-30T06:00:00.000Z",
              "median_rent": 4000,
              "monthly_change": "0.00",
              "quarterly_change": "-0.01",
              "yearly_change": "-0.07",
              "size_rank": 3,
              "created_at": "2017-08-27T00:27:45.140Z",
              "updated_at": "2017-08-27T00:27:45.140Z",
              "state": "NY",
              "metro": "New York",
              "county": "New York",
              "city": "New York"
            }
          ]
        ]
    }

PUT /api/v1/:regionType/:id
  • Description: Update the information for a single location
  • Parameters
    • regionType: The table you wish to modify
    • id: the id of the item you wish to change
    • [OPTIONS]
    • name (must be unique)
    • collected_on
    • median_rent
    • monthly_change
    • quarterly_change
    • yearly_change
    • size_rank (must be unique)
    • state (all except state table)
    • abbr (state table only)
    • metro (city, neighborhood, zipcode tables only)
    • county (city, neighborhood, zipcode tables only)
    • city (neighborhood, zipcode tables only)
  • Return Format: A JSON object
  • Errors
    • 404 Table Not Found: The region type provided does not exist, confirm intended path.
    • 500 Server Error: There was an error modifying the requested records, try again.
    • You must be authorized to hit the endpoint: JSON web token was either not applied or invalid
  • Example
    • Request
    PUT '/api/v1/metro/23'
    Body:
    {     
        "median_rent": 9999,
        "monthly_change": "11.59",
        "quarterly_change": "0.00",
        "yearly_change": "999.33"
    }
    Authorization: 'some-valid-token'
    • Return
    {
    "msg": "1 record(s) successfully updated",
    "result": 1
    }

DELETE /api/v1/:regionType
  • Description: Delete all records in the specified table
  • Parameters
    • regionType: Region type to delete
  • Return Format: A JSON object with the number of records deleted
  • Errors
    • 404 Table Not Found: The region type provided does not exist, confirm intended path.
    • 500 Server Error: There was an error deleting the requested records, try again.
  • Example
    • Request
    DELETE /api/v1/neighborhood
    
    • Return
    {
        "result": 8
    }

DELETE /api/v1/:regionType/:id
  • Description: Delete a single record in the specified table
  • Parameters
    • regionType: Region type to delete record from
    • id: Record ID to delete
  • Return Format: The number of records deleted
  • Errors
    • 404 Table Not Found: The region type provided does not exist, confirm intended path.
    • 500 Server Error: There was an error deleting the requested records, try again.
  • Example
    • Request
    DELETE /api/v1/neighborhood/8
    
    • Return
    1

Contributors

George Goering : GitHub Profile

Lindsay Parker : GitHub Profile

byob's People

Contributors

lindsaywparker avatar ggoering avatar

Watchers

 avatar

Forkers

ggoering

byob's Issues

Remove secondary .gets in tests

Per feedback:

If you've asserted that the POST came back with a 201, you can generally assume that the length of the array has increased. Having multiple requests in a single test block muddies is error prone and muddies the true source of a bug.

Endpoints -- 4 GET

  • 2 GET endpoints for all of one resource (i.e. ‘/api/v1/merchants’)
  • 2 GET endpoints for a specific resource (i.e. ‘/api/v1/merchants/:id’)

All endpoints should respond with a clear, informative error message and the minimum status code results:

  • 200/201: Success
  • 404: Not Found

If you have a critical server error, you should respond with

  • 500: Internal Server Error

Endpoints -- 2 DELETE

All endpoints should respond with a clear, informative error message and the minimum status code results:

  • 200/201: Success
  • 404: Not Found

If POST/PUT/PATCH request fails to save an entity due to bad information being sent from the client, you should respond with

  • 422: Unprocessable Entity

If you have a critical server error, you should respond with

  • 500: Internal Server Error

Root form submits email & app name to generate JWT

... that allows a user to request a JWT.

User must submit a username of ‘BobLoblaw’ and a password of ‘LawBlog’ in order to generate a JWT that will authenticate them for accessing all endpoints. Require the JWT by securing any ‘write’ requests (POST/PUT/PATCH/DELETE).

Endpoints -- 2 POST

All endpoints should respond with a clear, informative error message and the minimum status code results:

  • 200/201: Success
  • 404: Not Found

If POST/PUT/PATCH request fails to save an entity due to bad information being sent from the client, you should respond with

  • 422: Unprocessable Entity

If you have a critical server error, you should respond with

  • 500: Internal Server Error

Endpoints -- 2 PUT or PATCH

All endpoints should respond with a clear, informative error message and the minimum status code results:

  • 200/201: Success
  • 404: Not Found

If POST/PUT/PATCH request fails to save an entity due to bad information being sent from the client, you should respond with

  • 422: Unprocessable Entity

If you have a critical server error, you should respond with

  • 500: Internal Server Error

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.