Skip to content

This is a simple httpbin service built with fastapi for API testing. Main feature: Handle GET and POST requests automatically regardless of path parameter

License

Notifications You must be signed in to change notification settings

lonevle/fastapi-httpbin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

fastapi-httpbin

This is a simple httpbin service built with fastapi for API testing.

🇨🇳 中文

Features

  • Main feature: Handle GET and POST requests automatically regardless of path parameter

  • Support GET and POST requests

  • Auto return request info

    • Query params
    • Form data
    • JSON body
    • Request headers
    • File data (base64 encoded)
  • Add CORS support

Handle requests regardless of path, useful for testing proxy/nginx redirect

Usage

pip install fastapi
pip install uvicorn

python httpbin.py

Then you can send GET or POST requests to:

curl http://localhost:8010/get?foo=bar

It will return info like:

{
  "args": {
    "foo": "bar"  
  },
  "headers": {
    "Accept": "*/*",
    "Host": "localhost:8010", 
    "User-Agent": "curl/7.64.1"
  },
  "origin": "127.0.0.1",
  "url": "http://localhost:8010/get?foo=bar"
}

You can also use curl http://localhost:8010/post?foo=bar, path doesn't matter, only request type.

For POST requests, it will return form data, JSON and files:

curl -X POST http://localhost:8010/post -d 'foo=bar' -H 'Content-Type: application/json' -d '{"hello": "world"}' --data-binary '@file.txt' 
{
  "args": {},
  "data": "",  
  "files": {
    "file": "dGVzdCBmaWxlIGNvbnRlbnQ="
  },
  "form": {
    "foo": "bar"
  },
  "headers": {
    "Content-Type": "application/json",
    "Host": "localhost:8010",
    "Content-Length": "33"  
  },
  "json": {
    "hello": "world"
  },
  "origin": "127.0.0.1",
  "url": "http://localhost:8010/post" 
}

TODO

  • Support more request types
  • Return more request info
  • Add test cases

Feel free to contribute and open issues!

About

This is a simple httpbin service built with fastapi for API testing. Main feature: Handle GET and POST requests automatically regardless of path parameter

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages