Skip to content

dastan-myrsaliev/fastapi-training-task-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastapi_training_task_backend

A test assignment project built with FastAPI. The service provides basic URL shortening functionality and demonstrates handling of asynchronous requests.

Features

  • 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.

Requirements

  • Python 3.13+
  • Install dependencies:
pip install -r requirements.txt

Running the Server

To start the server with Uvicorn:

uvicorn app.main:app --reload --host 127.0.0.1 --port 8080

Example Requests

Shorten a URL

Request:

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.

Redirect to Original

Request:

GET /{shorten_id}

Response:

Running Tests

This project uses pytest.

To run the tests:

pytest

About

A training backend service built with FastAPI. Implements URL shortening: POST / to shorten, GET /{id} to redirect to original. Also includes an example of async request to an external API. Runs at http://127.0.0.1:8080 (configurable).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors