Giter Site home page Giter Site logo

api-design's Introduction

API Documentation

Introduction

This API allows users find information about people in the neighbourhood. Users can:

  • store people, houses and addresses
  • look up a house, its address and owner
  • look up people in our neighbourhood within certain age brackets and with specific household sizes

Database schema

This database uses relational data. alt text

RESTful Routes

Methods available in the API

HTTP verb Path Action
GET /people/new new entry for a person
POST /people create new entry
GET /people/:id show individual entry

Store People

Provide interface for storing new people.

  • URL

    /people/new

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 404 NOT FOUND
      Content: { error : "Page doesn't exist" }

Store People

Store new people.

  • URL

    /people/

  • Method:

    POST

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 201
      Content: { id : 1, firstName:'John' , lastName:'Smith', Age: 50, peopleInHousehold: 2 }
  • Error Response:

    • Code: 400 Bad Request
      Content: { error : "Bad Request" }
  • Sample Call:

    const options = {
        method: "POST",
        body: JSON.stringify(post),
        headers: {
          "content-type": "application/json",
        },
      };
    
      fetch(`${domain}/posts
      `,options)
      .then((r)=>r.json())
      .then((message) => {console.log(message)})
    
    });

Store Houses

Provide interface for storing new houses.

  • URL

    /houses/new

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 404 NOT FOUND
      Content: { error : "Page doesn't exist" }

Store Houses

Store new houses.

  • URL

    /houses/

  • Method:

    POST

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 201
      Content: { id : 1, Address: 1 Nowhere Avenue, lastName:'Smith', Age: 50, peopleInHousehold: 2 }
  • Error Response:

    • Code: 400 Bad Request
      Content: { error : "Bad Request" }
  • Sample Call:

    const options = {
        method: "POST",
        body: JSON.stringify(post),
        headers: {
          "content-type": "application/json",
        },
      };
    
      fetch(`${domain}/houses
      `,options)
      .then((r)=>r.json())
      .then((message) => {console.log(message)})
    
    });

Store Addresses

Provide interface for storing new address.

  • URL

    /address/new

  • Method:

    GET

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 200
  • Error Response:

    • Code: 404 NOT FOUND
      Content: { error : "Page doesn't exist" }

Store Houses

Store new houses.

  • URL

    /addresses/

  • Method:

    POST

  • URL Params

    None

  • Data Params

    None

  • Success Response:

    • Code: 201
      Content: { Postcode: 'N15 2XY', StreetAddress: 'Green Lanes' }
  • Error Response:

    • Code: 400 Bad Request
      Content: { error : "Bad Request" }
  • Sample Call:

    const options = {
        method: "POST",
        body: JSON.stringify(post),
        headers: {
          "content-type": "application/json",
        },
      };
    
      fetch(`${domain}/addresses
      `,options)
      .then((r)=>r.json())
      .then((message) => {console.log(message)})
    
    });

Get Houses

Get houses.

  • URL

    /houses/:id

  • Method:

    GET

  • URL Params

    None

    Required:

    id=[integer]

  • Data Params

    None

  • Success Response:

    • Code: 200
      Content: { id : 1, Address: 1 Nowhere Avenue, lastName:'Smith', Age: 50, peopleInHousehold: 2 }
  • Error Response:

    • Code: 400 Bad Request
      Content: { error : "Bad Request" }
  • Sample Call:

      fetch(`${domain}/${URL}
      `)
      .then((r)=>r.json())
      .then((message) => {console.log(message)})
    
    });

Get the address of a house

Get the address of a house.

  • URL

    /houses/:id/address

  • Method:

    GET

  • URL Params

    None

    Required:

    id=[integer]

  • Data Params

    None

  • Success Response:

    • Code: 200
      Content: { Address: 1 Nowhere Avenue, lastName:'Smith' }
  • Error Response:

    • Code: 400 Bad Request
      Content: { error : "Bad Request" }
  • Sample Call:

      fetch(`${domain}/${URL}
      `)
      .then((r)=>r.json())
      .then((message) => {console.log(message)})
    
    });

Get the owner of a house

Get the owner of a house.

  • URL

    /houses/:id/owner

  • Method:

    GET

  • URL Params

    None

    Required:

    id=[integer]

  • Data Params

    None

  • Success Response:

    • Code: 200
      Content: { Owner: 'John Smith'}
  • Error Response:

    • Code: 400 Bad Request
      Content: { error : "Bad Request" }
  • Sample Call:

      fetch(`${domain}/${URL}
      `)
      .then((r)=>r.json())
      .then((message) => {console.log(message)})
    
    });

Look up people with certain age brackets and specific household sizes

Query example for people over 25 with a household size of over 2

  • URL

/people:id?minAge=25&houshold?minSize=2

  • Method:

    GET

  • URL Params

    None

    Required:

    id=[integer] minAge=[integer] household?minSize = [integer]

  • Data Params

    None

  • Success Response:

    • Code: 200
      Content:{ id : 1, firstName:'John' , lastName:'Smith', Age: 50, peopleInHousehold: 3 }
  • Error Response:

    • Code: 400 Bad Request
      Content: { error : "Bad Request" }
  • Sample Call:

      fetch(`${domain}/${URL}
      `)
      .then((r)=>r.json())
      .then((message) => {console.log(message)})
    
    });

api-design's People

Contributors

derejmi avatar gerinz avatar

Watchers

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