An echo service with throttling to limit the number of API requests made in a certain period.
The /echo endpoint of the service should return the request body as is if the current number of requests per running minute does not exceed the set rate limit. Otherwise, the endpoint should respond with an error.
The /rate endpoint can be used to obtain the critical request rate and to set it to a new value.
- Python ^3.10
- Redis Server
Install dependencies and start app on local
>> pip3 install poetry |# install dependency manager|
>> poetry shell |# activate virtual environment for app dependencies|
>> poetry install |# install app dependencies|
>> python3 main.py |# start the application|
voila!!! You can now make your API requests according to the API Reference section below
Install dependencies and start app using docker
>> chmod +x deploy.sh |# make the script executable|
>> sh deploy.sh |# execute docker shell script to create the docker containers|
voila!!! You can now make your API requests according to the API Reference section below
To run this project, you will need to add the following environment variables to your .env file
APP_HOST
APP_PORT
REDIS_HOST
REDIS_PORT
To run tests, run the following command in project root directory
pytest
API Reference [http://127.0.0.1:8000/docs]
Accepts a JSON payload and responds back with the same payload if API rate limit isn't exceeded
POST /echo
Sample JSON Request payload
{
"api_throttling": "testing"
}
Retrieves the number of requests per running minute
GET /rate
Sample JSON Response payload
{
"rate_limit": "25"
}
Set the number of requests per running minute
POST /rate
Sample JSON Request payload
{
"rate_limit": "25"
}
Sample JSON Response payload
{
"rate_limit": "25"
}