Skip to content

Commit

Permalink
Merge pull request #11 from tbobm/feat/add-http-api-dump
Browse files Browse the repository at this point in the history
Add HTTP API dump
  • Loading branch information
tbobm authored Apr 19, 2024
2 parents 8c39bcd + 8bb0ad4 commit e750f5b
Show file tree
Hide file tree
Showing 5 changed files with 371 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ $ curl localhost:8000/health
OK
```

#### http-dump

Path: [`./api/http/dump/`](./api/http/dump/)

Example usage:
```console
$ docker run -p 8000:8000 -d --rm ghcr.io/tbobm/apps:api-http-dump-latest
$ curl localhost:8000/any/path -H "example-header: any-value"
{"path":"any/path","method":"GET","headers":{"host":"localhost:8000","user-agent":"curl/7.81.0","accept":"*/*","example-header":"any-value"},"form":{}}
```

## SQS

### Producer
Expand Down
14 changes: 14 additions & 0 deletions api/http/dump/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.12-slim as release

WORKDIR /app

EXPOSE 8000
RUN pip install poetry
# NOTE: could implement healthcheck

# install dependencies
COPY . .

RUN poetry install

ENTRYPOINT [ "poetry", "run", "uvicorn", "dump.main:app", "--host", "0.0.0.0" ]
26 changes: 26 additions & 0 deletions api/http/dump/dump/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from typing import Union

from fastapi import FastAPI, Request

app = FastAPI()


@app.api_route("/{full_path:path}", methods=["HEAD", "GET", "POST", "DELETE", "PUT"])
async def read_root(request: Request, full_path: str):
response = {
"path": full_path,
"method": request.method,
}
response['headers'] = request.headers
_json = None
try:
_json = await request.json()
if _json is not None:
response['json'] = _json
except Exception:
# no json payload
pass
_form = await request.form()
if _form is not None:
response['form'] = _form
return response
Loading

0 comments on commit e750f5b

Please sign in to comment.