A test assignment project built with FastAPI. The service provides basic URL shortening functionality and demonstrates handling of asynchronous requests.
POST /— Accepts a long URL and returns a shortened version (HTTP 201).GET /{shorten_id}— Redirects to the original URL (HTTP 307).- Example of an async request to an external API.
- Python 3.13+
- Install dependencies:
pip install -r requirements.txtTo start the server with Uvicorn:
uvicorn app.main:app --reload --host 127.0.0.1 --port 8080Request:
POST /
Content-Type: application/json
{
"url": "https://example.com"
}Response:
{
"shorten_url": "http://127.0.0.1:8080/{shorten_id}"
}Note: {shorten_id} will be a random string generated for each URL.
Request:
GET /{shorten_id}Response:
-
Status: 307 Temporary Redirect
-
Header: Location: https://example.com
To run the tests:
pytest