Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 3.97 KB

File metadata and controls

50 lines (39 loc) · 3.97 KB

Room Auction API

Read pleaseTASK.md for baseline conditions

API point Method Request headers Request body / params Response headers HTTP Status / Response body
/ GET 200 / {status, version}
/auth POST Content-Type: application/x-www-form-urlencoded, Authorization: Basic {grant_type: password, client_id, client_secret, username, password} 501 if wrong grant type, 401 if wrong client id/secret, 403 if wrong username/password / {error, error-description}, 200 / {access_token, refresh_token, expires_in, token_type}
/auth POST Content-Type: application/x-www-form-urlencoded {grant_type: refresh_token, client_id, client_secret, refresh_token} 200 / {access_token, refresh_token, expires_in, token_type}
/rooms GET Authorization: Bearer ${token} all: true/false (or none), page (limit is fixed to 20) WWW-Authenticate will contain auth errors details if any 200 / {docs, total, limit, page, pages} or status according to error
/rooms/:roomId GET -- same with previous -- -- same with previous -- 200 / {room} or status according to error
/rooms POST Content-Type: application/x-www-form-urlencoded, Authorization: Bearer ${token} {minPrice, description} WWW-Authenticate, Location 201 / {savedRoom} or status according to error
/bids GET Authorization: Bearer ${token} page (limit is fixed to 20) WWW-Authenticate will contain auth errors details if any 200 / {docs, total, limit, page, pages} or status according to error
/bids/:bidId GET -- same with previous -- WWW-Authenticate will contain auth errors details if any 200 / {bid} or status according to error
/bids POST Content-Type: application/x-www-form-urlencoded, Authorization: Bearer ${token} {roomId, price} WWW-Authenticate, Location 201 / {savedBid} or status according to error

Flow:

  • Users can GET / info about current API status and version;
  • Users have to authorize by POST /auth with relevant query headers and body (OAuth2 password grant flow is used);
  • In case of obsolete token users can renew it by POST /auth with relevant query headers and body;
  • Registered users with the appropriate authority POST /rooms new room for auction (it will start immediately and server emit "New room" event with all necessary details to the "news" room);
  • Registered users can GET /rooms rooms with active auctions (default behaviour) or all rooms (query param ?all=true);
  • Registered users can connect to socket server https://power-buffet.glitch.me immediately after connection user have to:
   .on('connect', () => {  
     client.emit('auth', {token: _place_valid_token_here_});
   })

      or connection to server will be interrupted.

  • Registered users can POST /bids new bid according with the rules, server emit "New bid" event with all necessary details to the "news" room;
  • Registered users can GET /rooms/:roomId all info for ${roomId} room (including dynamically populated list of all registered bids for this room);
  • Registered users can GET /bids/:bidId all info for ${bidId} bid (including actual info about associated room);

Docs:

There are exported environment and collection for Postman. It's easy to change some queries (params such as roomId etc.) and try all API points with pre-populated data.

Scripts:

  • npm run initialPopulation will drop all tables in DB an populate it with data from initialPopulation.json;
  • npm run eslint will start ESlint and check project according to .eslintrc;
  • npm run test will start Mocha for run tests from test directory;
  • npm run start will start project locally (you have to run npm install first);