Tech challenge practice. RESTful API built from scratch.
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/
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.
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:
- Create a market price.
- Create your stock You can also check a specific stock, change your stock name and remove it from the list.
curl -s http://stock--api.herokuapp.com/api/v1/bearers/1
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.
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
curl -s http://stock--api.herokuapp.com/api/v1/bearers/1
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/
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
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
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
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.