Giter VIP home page Giter VIP logo

fastapi-httpbin's Introduction

FastAPI Httpbin

HTTP Endpoints for easy testing of your app.

Built with the FastAPI Framework for Python, this is heavily based on the original Httpbin website.

Play with it in production at https://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:

Differences between this app and Httpbin

  • 100% unit test coverage of all endpoints.
  • Ensured that documentation 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)

Development

To run FastAPI Httpbin in development mode so that changes to the underlying Python files are 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:
    • ./bin/docker-build.sh - Build the Docker container
    • ./bin/docker-dev.sh - Start the Docker container and spawn a bash shell so that scripts can be run from inside the container.
      • Note that the host directory lives in /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
      • Or run ./bin/dev.sh, however changes to files may not be caught.

Deployment

  • 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.
  • ./bin/docker-push.sh - This will push the Docker image to Docker Hub

In production

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

FAQ: Are there any bugs?

Docker-in-Vagrant Issues

If you are running Docker from Vagrant, the app won't behave 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.

Get In Touch

If you run into any problems, feel free to open an issue.

Otherwise, you can find me on Twitter, Facebook, or drop me an email: doug.muth AT gmail DOT com.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.