Add README.md
This commit is contained in:
@@ -0,0 +1,42 @@
|
|||||||
|
# Minimal ASGI Middleware
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
This repository contains a simple ASGI middleware implementation that can be used with frameworks such as FastAPI or Starlette. It logs the path of every incoming HTTP request.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
No external dependencies are required. Just copy the files into your project.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# If you prefer a virtual environment
|
||||||
|
python -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
|
||||||
|
# Install any dependencies (none for this minimal example)
|
||||||
|
# pip install -r requirements.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Import the `get_middleware` helper and wrap your ASGI application:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from fastapi import FastAPI
|
||||||
|
from middleware import get_middleware
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
app = get_middleware(app)
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
async def root():
|
||||||
|
return {"message": "Hello World"}
|
||||||
|
```
|
||||||
|
|
||||||
|
Run the app with Uvicorn or any ASGI server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
uvicorn main:app --reload
|
||||||
|
```
|
||||||
|
|
||||||
|
You should see log messages for each request in the console.
|
||||||
|
|
||||||
|
## License
|
||||||
|
MIT
|
||||||
Reference in New Issue
Block a user