This project is a API with Node.js to allow users to get stock quotes. It consists of two separate services:
- API Service: Handles user requests for stock quotes and manages user registration, authentication, stats and history tracking.
- Stock Service: Fetch an external API to retrieve stock information.
- Docker and Docker Compose installed on your machine.
-
Build and start the services using Docker Compose:
docker-compose up --build
-
The service will be available at:
- API Service:
http://localhost:3003
- API Service:
Both the API service and the Stock service require environment variables to be set for configuration. All the environment files will be sent in the e-mail of challenge delivering
-
Endpoint:
POST /register
-
Description: Registers a new user with the provided email and role.
-
Request Body:
{ "email": "peterparker@spiderman.com", "role": "user" }
-
Response Body:
{ "email": "peterparker@spiderman.com", "password": "tehr23jl" }
-
Endpoint:
GET /stock?q={stock_code}
-
Description: Retrieves the stock quote for the specified stock code.
-
Query Parameters: Replace
{stock_code}
with the desired stock code. -
Response Body Example:
{ "name": "APPLE", "symbol": "AAPL.US", "open": 123.66, "high": 123.66, "low": 122.49, "close": 123 }
-
Endpoint:
GET /history
-
Description: Retrieves the user's stock quotes history.
-
Response Body Example:
[ { "date": "2021-04-01T19:20:30Z", "name": "APPLE", "symbol": "AAPL.US", "open": 123.66, "high": 123.66, "low": 122.49, "close": 123 }, { "date": "2021-03-25T11:10:55Z", "name": "APPLE", "symbol": "AAPL.US", "open": 121.10, "high": 123.66, "low": 122, "close": 122 } ]
-
Endpoint:
GET /stats
-
Description: Retrieves the top 5 most requested stocks.
-
Response Body Example:
[ { "stock": "AAPL.US", "times_requested": 5 }, { "stock": "MSFT.US", "times_requested": 2 } ]
-
Endpoint:
POST /reset-password
-
Description: Resets the user's password and sends the new password via email.
-
Request Body:
{ "email": "brucewayne@batman.com" }
To run the unit and integration tests:
-
Ensure the services are running.
-
Execute the tests using npm:
cd api-service npm test
cd ../stock-service npm test
The API documentation is available at http://localhost:3003/api-docs
once the services are running.