Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/milisp/miniapi
light FastAPI
https://github.com/milisp/miniapi
fastapi
Last synced: 3 months ago
JSON representation
light FastAPI
- Host: GitHub
- URL: https://github.com/milisp/miniapi
- Owner: milisp
- Created: 2024-10-28T10:01:16.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-10-28T13:35:23.000Z (3 months ago)
- Last Synced: 2024-10-28T13:47:06.114Z (3 months ago)
- Topics: fastapi
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MiniAPI
A lightweight Python web framework inspired by FastAPI, featuring async support, WebSocket capabilities, and middleware.
## Features
- Async request handling
- Route parameters
- WebSocket support
- Middleware system
- Request validation
- CORS support
- Form data handling
- ASGI compatibility## Installation
```bash
pip install miniapi3
```For WebSocket support:
```bash
pip install miniapi3[websockets]
```## Quick Start
```python
from miniapi3 import MiniAPI, Responseapp = MiniAPI()
@app.get("/")
async def hello():
return {"message": "Hello, World!"}@app.get("/users/{user_id}")
async def get_user(request):
user_id = request.path_params["user_id"]
return {"user_id": user_id}# WebSocket example
@app.websocket("/ws")
async def websocket_handler(ws):
while True:
message = await ws.receive()
await ws.send(f"Echo: {message}")if __name__ == "__main__":
app.run()
```## Request Validation
```python
from dataclasses import dataclassfrom miniapi3.validation import RequestValidator, ValidationError
from miniapi3 import MiniAPI, Responseapp = MiniAPI()
@dataclass
class UserCreate(RequestValidator):
username: str
email: str
age: int@app.post("/users")
@app.validate(UserCreate)
async def create_user(request, data: UserCreate):
return {"user": data}
```## CORS Middleware
```python
from miniapi3 import MiniAPI, CORSMiddlewareapp = MiniAPI()
app.add_middleware(CORSMiddleware, allow_origins=["*"])
```## HTML Response
```python
from miniapi3 import MiniAPI, htmlapp = MiniAPI()
@app.get("/")
async def index():
return html("Hello, World!
")
```