Create an API that takes a number and returns interesting mathematical properties about it, along with a fun fact. Weight: 6 points Requirements
Technology Stack:
Use any programming language or framework of your choice (See Sharp (C #), PHP :elephant:, Python :snake:, Go :runner::skin-tone-5:, Java :coffee:, JS/TS :nauseated_face:)
Must be deployed to a publicly accessible endpoint
Must handle CORS (Cross-Origin Resource Sharing)
Must return responses in JSON format
Version Control:
Code must be hosted on GitHub
Repository must be public
Must include a well-structured README.md
API Specification
Endpoint: **GET** <your-url>/api/classify-number?number=371
Required JSON Response Format (200 OK):
{
"number": 371,
"is_prime": false,
"is_perfect": false,
"properties": ["armstrong", "odd"],
"digit_sum": 11, // sum of its digits
"fun_fact": "371 is an Armstrong number because 3^3 + 7^3 + 1^3 = 371"
}
Required JSON Response Format (400 Bad Request)
{
"number": "alphabet",
"error": true
}
Deployment
Publicly accessible and stable API.
Fast response time (< 500ms).
Additional Note
Use the math type from the Numbers API to get the fun fact.
The possible combinations for the properties field:
["armstrong", "odd"] - if the number is both an Armstrong number and odd
["armstrong", “even”] - if the number is an Armstrong number and even
["odd"] - if the number is not an Armstrong number but is odd
[”even”] - if the number is not an Armstrong number but is even
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
mkdir package
pip install --target ./package -r requirements.txt
cp main.py package/
cd package
zip -r ../deployment.zip .
cd ..
aws lambda create-function \
--function-name number-classifier \
--runtime python3.9 \
--handler lambda_function.handler \
--role arn:aws:iam::[YOUR-ACCOUNT-ID]:role/[YOUR-LAMBDA-ROLE] \
--zip-file fileb://deployment.zip \
--timeout 30 \
--memory-size 256
aws lambda update-function-code \
--function-name number-classifier \
--zip-file fileb://deployment.zip
Set up API Gateway:
aws apigateway create-rest-api \
--name "Number-Classifier-API" \
--description "Number Classification API"
API_ID=$(aws apigateway get-rest-apis --query "items[?name=='Number-Classifier-API'].id" --output text)
ROOT_RESOURCE_ID=$(aws apigateway get-resources --rest-api-id $API_ID --query "items[?path=='/'].id" --output text)
aws apigateway create-resource \
--rest-api-id $API_ID \
--parent-id $ROOT_RESOURCE_ID \
--path-part "api"
aws apigateway put-method \
--rest-api-id $API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--authorization-type NONE
aws apigateway put-integration \
--rest-api-id $API_ID \
--resource-id $RESOURCE_ID \
--http-method GET \
--type AWS_PROXY \
--integration-http-method POST \
--uri arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${LAMBDA_ARN}/invocations
aws apigateway create-deployment \
--rest-api-id $API_ID \
--stage-name prod