The answer.js
file contains the following:
'use strict'
const {
PORT
} = process.env
function fibonacci (num) {
let a = 1
let b = 0
let temp
while (num >= 0) {
temp = a
a = a + b
b = temp
num--
}
return b
}
Using the Node-core API's or any framework or libraries of your choice, build a web-server listening for requests on PORT
.
This server should have a single endpoint /calculate-fibonacci
responding to GET, returning 404 for other routes and methods.
/calculate-fibonacci
should merely allow an URL query parameter called digit
, and respond to these codes managing the following scenarios:
- if
digit
is missing - status code 400 - if extra URL query parameters are received - 406
- if digit is not an integer - 400
- if digit is greater than 50 - 413
If any of the exceptions above occur, The endpoint should return the result of the fibonacci function for digit
with a status code of 200 along with a json result, in the following format:
{
"digit": original digit here,
"result": result of the fibonacci function here
}