Metadata-Version: 2.5
Name: minihttp
Version: 0.1.0
Summary: minihttp is a lightweight server written in pure python
Author-email: Mizuki Hikaru <mizuki@hikaru.org>
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# minihttp

minihttp is a small production ready HTTP server that implements subset of the
HTTP protocol. For example, it only supports GET and POST and always closes the
connection.

Path parameters are bound by name. A handler may define one request-data
argument: for GET requests the entire query string is deserialized into that
argument's annotated type, and for POST requests the entire JSON body is
deserialized into it. A handler may also define one argument annotated as
`Headers`, which receives the request headers with case-insensitive lookups.

## Usage

```python
from dataclasses import dataclass

from minihttp import Headers, Server


@dataclass
class UserQuery:
    sort_by: str


@dataclass
class Group:
    name: str
    active: bool = True


server = Server()


@server.get("/groups/:group_id")
def users(group_id: int, query: UserQuery, headers: Headers):
    # GET /groups/7?sort_by=name turns the query string into
    # UserQuery(sort_by="name"). Header lookup is case-insensitive.
    request_id = headers.get("X-Request-ID")
    return [group_id, query.sort_by, request_id]


@server.post("/groups/new")
def new_group(group: Group):
    # A JSON body such as {"name":"admins","active":false} is
    # deserialized directly into Group("admins", False).
    return group


server.run("0.0.0.0", 2000)
```
