Server Planner Api These are solutions to the Backend Developer take home test for Trium Tech
The Live Application is deployed on heroku at https://trium-server.herokuapp.com/ or can be cloned from github.com.
Begin by cloning the repository, cd
into the cloned repository and run the following:
npm install
This command installs all the necessary dependencies
Create a .env
using the .env.example
file as a guide, using your local environment variables
npm run dev
If all goes well, you should see something similar to this on the console:
Application started on http://localhost:<port>
The API is built for easy use and understanding. It includes the following:
- Endpoint to input, calculate and return the number of servers based on serverTypes and virtualMachines inputted.
EndPoint | Functionality |
---|---|
POST /api/v1/calculate |
return number of servers |
Now you can test the endpoints with a client e.g POSTMAN
List of commands available at the moment include:
POST
Adds an entry into the database
/api/v1/calculate - adds a user to the database. The user information is sent within the Body of the request and it returns an of object that contains the HTTP status code and result which is the number of servers. Input format:
{
"serverType": {"CPU": 2, "RAM": 32, "HDD": 100},
"virtualMachines": [{"CPU": 1, "RAM": 16, "HDD": 10}, {"CPU": 1, "RAM": 16, "HDD": 10}, {"CPU": 2, "RAM": 32, "HDD": 100}]
}
Sample response on success
{
"success": true,
"statusCode": 201,
"message": "Server count successfully calculated",
"result": 2
}
Each input field is validated and would return a field specific error message if empty.
{
"success": false,
"statusCode": 400,
"message": "Request Failed",
"err": {
"serverType": "serverType must be an object"
}
}
To test the endpoints, create a test database and run the following:
npm run test
To run the Application on docker. Input the following in your terminal
chmod +x ./start.sh
./start.sh
If all goes well, you should see something similar to this on the console:
Application started on http://localhost:5000
API is deployed on Heroku
- Node.js - Javascript runtime
- Express - Web application framework
- Jest and Supertest - testing framework
- Ulor Pascal - PascalUlor