make install # install deps
make test # run tests
make lint # run linter
make start # start server for Shapes api
Install and start server (see commands above)
Endpoint POST localhost:8000/shapes/calculate
params:
- shape -
triangle
,circle
,square
- method: -
perimeter
,area
- params (depends on shape type):
- Square:
side
- Triangle:
sideA
,sideB
,sideC
- Circle:
radius
- Square:
Examples:
Calculate Triangle perimeter:
curl -X POST \
'localhost:8000/shapes/calculate' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"shape": "triangle",
"method": "perimeter",
"params": {
"sideA": 3,
"sideB": 5,
"sideC": 7
}
}'
Response:
{
"data": {
"method": "perimeter",
"shape": "triangle",
"result": 15
}
}
Square area:
curl -X POST \
'localhost:8000/shapes/calculate' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"shape": "square",
"method": "area",
"params": {
"side": 5
}
}'
Response:
{
"data": {
"method": "area",
"shape": "square",
"result": 25
}
}
Circle area:
curl -X POST \
'localhost:8000/shapes/calculate' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"shape": "circle",
"method": "area",
"params": {
"radius": 5
}
}'
Response:
{
"data": {
"method": "area",
"shape": "circle",
"result": 78.53981633974483
}
}
Works with float values
curl -X POST \
'localhost:8000/shapes/calculate' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--data-raw '{
"shape": "square",
"method": "area",
"params": {
"side": 5.0
}
}'
Response:
{
"data": {
"method": "area",
"shape": "square",
"result": 25
}
}
Validation errors:
{
"message": "side should be integer or float"
}
{
"message": "side is required"
}
{
"message": "round is invalid method, valid methods: perimeter, area"
}
{
"message": "round is invalid shape type, valid types: triangle, circle, square"
}