Skip to content

Latest commit

 

History

History
115 lines (95 loc) · 3.55 KB

README.md

File metadata and controls

115 lines (95 loc) · 3.55 KB

Stock Market API

Tech challenge practice. RESTful API built from scratch.

Table of contents

Overview

The idea here was to practice how to build a RESTful API.

Without login you can check an existing bearer any time.

For all other actions, you need an account.

All requests as application/json.

Base URL: https://stock--api.herokuapp.com/

Authentication

You need a client account to access this API. Inside te body of your resquest you need to provide email and password. We will respond with an authentication token.

Our authenticity token is generated by simple_token_authentication.

Workflow

First, you need to create a client account. We then will provide you an authentication token. Use your client account to create a bearer for you. Now, you can check all stocks that we have. If you want to create a stock:

  1. Create a market price.
  2. Create your stock You can also check a specific stock, change your stock name and remove it from the list.

Any time test

Check bearer

curl -s http://stock--api.herokuapp.com/api/v1/bearers/1

Reference

Create client

curl -i -X POST \
  -H 'Content-Type: application/json' \
  -d '{ "user": { "email": "<YOU@EMAIL>", "password": "<YOUR_PASSWORD>" } }' \
  https://stock--api.herokuapp.com/api/v1/clients

Use your token to create a bearer. Only bearers can CRUD stocks.

Create bearer

curl -i -X POST \
  -H 'Content-Type: application/json' \
  -H 'X-User-Email: <YOU@EMAIL>' \
  -H 'X-User-Token: <YOUR_TOKEN>' \
  -d '{ "name": "<BEARER_NAME>" }' \
  https://stock--api.herokuapp.com/api/v1/bearers

Check bearer

curl -s http://stock--api.herokuapp.com/api/v1/bearers/1

Check stocks

curl -i -X GET \
  -H 'Content-Type: application/json' \
  -H 'X-User-Email: <YOU@EMAIL>' \
  -H 'X-User-Token: <YOUR_TOKEN>' \
  https://stock--api.herokuapp.com/api/v1/stocks/

Create market price

curl -i -X POST \
  -H 'Content-Type: application/json' \
  -H 'X-User-Email: <YOU@EMAIL>' \
  -H 'X-User-Token: <YOUR_TOKEN>' \
  -d '{ "value_cents": "<INTEGER>", "currency": "<STRING>" }' \
  https://stock--api.herokuapp.com/api/v1/market_prices

Create stock

curl -i -X POST \
  -H 'Content-Type: application/json' \
  -H 'X-User-Email: <YOU@EMAIL>' \
  -H 'X-User-Token: <YOUR_TOKEN>' \
  -d '{ "name": "<STOCK_NAME", "market_price_id": "<ID>", "bearer_id": "<YOUR_BEARER_ID>" }' \
  https://stock--api.herokuapp.com/api/v1/stocks

Edit stock

curl -i -X PUT \
  -H 'Content-Type: application/json' \
  -H 'X-User-Email: <YOU@EMAIL>' \
  -H 'X-User-Token: <YOUR_TOKEN>' \
  -d '{ "name": "<NEW_STOCK_NAME>", "market_price_id": "1", "bearer_id": "1" }' \
  https://stock--api.herokuapp.com/api/v1/stock/:stock_id

Delete stock

curl -i -X DELETE \
  -H 'Content-Type: application/json' \
  -H 'X-User-Email: <YOU@EMAIL>' \
  -H 'X-User-Token: <YOUR_TOKEN>' \
  -d '{ "bearer_id": "<YOUR_BEARER_ID>"}' \
  https://stock--api.herokuapp.com/api/v1/stock/:stock_id

Rails app generated with lewagon/rails-templates, created by the Le Wagon coding bootcamp team.