This is a sample FastAPI project created to test deployment on DigitalOcean with CI/CD pipelines. The project contains two simple routes: a root route and an item route.
-
GET /
Returns a JSON response:{ "Hello": "World" }
-
GET /items/{item_id} Takes an
item_id
(integer) as a path parameter and an optional query parameterq
(string). Returns a JSON response:{ "item_id": item_id, "q": q }
├── main.py # Main FastAPI app with routes
├── requirements.txt # Python package dependencies
├── README.md # Project documentation (this file)
- Python 3.7+
- FastAPI
Follow the steps below to set up and run the project locally:
-
Clone the repository:
git clone git@github.com:hironate/fast-api-test-project.git cd fast-api-test-project
-
Create a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required dependencies:
pip install -r requirements.txt
To run the FastAPI app locally using FastAPI CLI, execute the following command:
fastapi dev run.py
To run the FastAPI app on production using FastAPI CLI, execute the following command:
fastapi run
This will start the development server with auto-reloading enabled. You should see output like:
INFO: Serving at http://127.0.0.1:8000
INFO: API docs: http://0.0.0.0:8000/docs
INFO: Running in production mode, for development use:
fastapi dev
Now, you can visit the following endpoints in your browser or API testing tool (e.g., Postman):
This project is licensed under the MIT License - see the LICENSE file for details.
### Key Steps Included:
- Cloning the repo
- Setting up a virtual environment
- Installing dependencies
- Running the FastAPI server locally
- Explaining the available routes and example usage