- Notifications
You must be signed in to change notification settings - Fork8
HTTP Endpoints for easy testing of your app.
License
dmuth/fastapi-httpbin
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
HTTP Endpoints for easy testing of your app.
Built with theFastAPI Framework for Python, this is heavily based on the originalHttpbin website.
Play with it in production athttps://httpbin.dmuth.org/ Documentation for all endpoints is right on the front page of the site. What are you waiting for? :-)
Also consider these add-ons I wrote which make use of the API:
- 100% unit test coverage of all endpoints.
- Ensured thatdocumentation 100% matches the responses returned.
- Ensured that all values are now sanity checked
- All endpoints with mandatory parameters now have examples in the documentation in order to reduce friction for test usage.
- Fixed a few bugs found in the implementation of the
/cache
endpoints in Httpbin. - Several endpoints have
GET
version only, as I did not see the point to supporting every possible HTTP verb--I felt that this just made the Swagger documentation unwieldly. (This is subject to change based on usage patters and demand)
To run FastAPI Httpbin in development mode so that changes to the underlying Python filesare automatically reloaded:
- Directly
pip install -r ./requirements.txt
PORT=9000 ./bin/dev.sh
- Run server in dev mode on port 9000, so that changes to the Python scripts cause them to be reloaded
- Or, in Docker if you'd prefer:
- Build the Docker container
./bin/docker-build.sh
- Start the Docker container and spawn a bash shell so that scripts can be run from inside the container.
./bin/docker-dev.sh
- Now that you're inside the container:
- Note that the host directory lives in
/mnt/
.cd /mnt
- Then run
./pytest.sh
- Run
./pytest.sh -v
to view individual test names as they run - Run
./pytest.sh -k NAME
to limit tests to a specific test by name
- Run
- Or run
./bin/dev.sh
, however changes to files may not be caught.- Access the website athttp://localhost:8000/
- Updating dependencies
- Remove versions from
requirements.txt
./bin/docker-build.sh && ./bin/docker-dev.sh
- This will re-download the latest requirements
cd /mnt
./pytest.sh -v
- Make sure unit tests pass
pip freeze > ./requirements.txt
- Save the latest versions to the requirements file
- Remove versions from
- Note that the host directory lives in
- Build the Docker container
- Bump version number in
./lib/fastapi.py
. ./bin/docker-build.sh
- Build the Docker container
./bin/deploy.sh
- This will run
fly deploy
to deploy the container on Fly.io.
- This will run
./bin/docker-push.sh
- This will push the Docker image to Docker Hub
./bin/prod.sh
- Run in production mode, so that changes made to the Python scripts do NOT cause reloads../bin/docker-prod.sh
- Run the Docker container in production mode (detached from the console).
Look ink8s/README.md for Kubernetes instructions. I built that out usingk3s with k3d, but those files should work reasonably well in a full blown k8s environment.
If you arerunning Docker from Vagrant, the app won'tbehave right when run in Development Mode inside of a container. Specifically, the functionality of FastAPI to reload itself when a file is changed does not seem to work. For now, the workaround is to restart the FastAPI server when new changes are to be tested, or to not run it in a container in the first place.
Production use is unaffected.
If you run into any problems, feel free toopen an issue.
Otherwise, you can find meon Twitter,Facebook, or drop me an email:doug.muth AT gmail DOT com.