REST API for 99 minutos
Service available on https://ninety-nine-minutos-tech-test.herokuapp.com/
You must have Node.js v14 installed
Create .env
file as .env.example
To run in develop mode
npm run dev
To run in production mode
npm start
This execute an API REST on localhost:${process.env.PORT}
To execute tests
npm test
path: /
method: GET
description: This endpoint returns a message that indicates if API is
working
response:
{
"message": "99 minutos app test works!"
}
path: /v1/b-trees/height
method: POST
description: This endpoint receives an array of numbers and converts it to a
binary tree to return the height of the tree
body:
{
"toTree":[9, 11, 13, 6, 12, 17, 8, 18, 2, 0]
}
response:
{
"height": 5
}
path: /v1/b-trees/neighbors
method: POST
description: This endpoint receives an array of numbers and a node.
convert the array to a binary tree and find node in tree to return its
neighbors
body:
{
"toTree":[9, 11, 13, 6, 12, 17, 8, 18, 2, 0],
"node": 9
}
response:
{
"neighbors": {
"left": 6,
"right": 11
}
}
path: /v1/b-trees/bfs
method: POST
description: This endpoint receives an array of numbers and converts it to a
binary tree to return an array of tree nodes readed breadth first transversal
body:
{
"toTree":[9, 11, 13, 6, 12, 17, 8, 18, 2, 0]
}
response:
{
"bfs": [9, 6, 11, 2, 8, 13, 0, 12, 17, 18]
}
All errors have the same structure
This is the Node not found in tree error for develop mode
{
"statusCode": 404,
"error": "Not Found",
"message": "Node is not found in tree",
"stack": "Error: Node is not found in tree\n at Tree.getNode..."
}
This is the Node not found in tree error for production mode
{
"statusCode": 404,
"error": "Not Found",
"message": "Node is not found in tree"
}
The first element on array is the head of the tree, following element is located on the right if it's bigger than the head or on the left if it's lower.
If right or left is already filled, it will be positioned the same with respect to that node.
Edwin García
spark.com.co@gmail.com