This project showcases a FastAPI application developed within a VSCode Dev Container.
The FastAPI application provides a simple endpoint at the root (/) that returns the current Unix timestamp. You can access the API Swagger documentation by navigating to the /docs endpoint.
- Open the project in VSCode.
- When prompted, open the project inside the container. (Or press
F1, typeRemote-Containers: Reopen in Container). - Once inside the container, open VSCode Terminal at the root of the project and run these commands:
cd src
uvicorn main:app --port <PORT>
This will start the FastAPI application, and you can access it on port
- Visit
http://localhost:<PORT>in your browser to see the current Unix timestamp returned by the FastAPI app. - Access the API Swagger docs at
http://localhost:<PORT>/docs.
Open a VsCode Terminal at the root of the project and run:
python -m unittest discover -s tests- Open the project in VSCode.
- Open a VSCode Terminal at the root of the project. Then run these commands:
docker build -t fastapi-app . docker run -d -p <EXTERNAL_PORT>:<INTERNAL_PORT> fastapi-app
- <EXTERNAL_PORT>: The port on your machine/host you want to access the app through.
- <INTERNAL_PORT>: The port inside the Docker container (set in the
Dockerfile).
- Visit
http://localhost:<EXTERNAL_PORT>/in your browser to see the current Unix timestamp returned by the FastAPI app. - Access the API Swagger docs at
http://localhost:<EXTERNAL_PORT>/docs.
The project currently uses uvicorn as its ASGI server, as specified in the requirements.txt file. If you wish to use another ASGI server like hypercorn or daphne, simply update the requirements.txt file and modify the startup command accordingly in the devcontainer.json file and the Dockerfile. Make sure the server you choose is compatible with FastAPI.