Lightweight HTTP server library for microcontrollers.
Project description
netcorelink/microhttpx
Lightweight HTTP server library for microcontrollers
netcorelink/microhttpx is a lightweight HTTP server library for microcontrollers.
Install by pip microhttpx
pip install microhttpx
Install by MicroPython microhttpx
For MicroPython, installation is performed by copying microhttpx/* the library files to the device's file system.
example: microhttpx/* - :lib/*
A quick example
Route
from microhttpx.status import StatusOK
from microhttpx import HttpxServer, HttpxRequest, HttpxResponse
server = HttpxServer()
@server.route("/hello", methods=("GET",))
def get_hello(req: HttpxRequest):
return HttpxResponse.json(req.conn, StatusOK(), {"message": "Hello, world!"})
server.listen(port=8080)
Structs
from microhttpx import HttpxStruct, HttpxField
class GetUsersStruct(HttpxStruct):
__route__ = "/users/{uuid}"
__fields__ = {
"uuid": HttpxField(str, required=True),
"expand": HttpxField(str, required=False, default="basic"),
}
uuid: str
expand: str
| Argument | Type | Default value | Description |
|---|---|---|---|
| field_type | type | str | Field type (str, int, float, bool, etc.). The value is automatically converted during parsing. |
| required | bool | False | Is the field required. If True and the field is missing, a ValueError is thrown. |
| default | any | None | The default value for an optional field. is used if no value is passed. |
| validator | Callable[[any], bool] | None | A function to check the value of a field. It should return True if the value is valid. If False, an error is thrown. |
usage struct in route:
@server.route("/users/{uuid}")
def get_user(req: HttpxRequest):
try:
user = GetUsersStruct(req)
except ValueError as e:
return {"error": str(e)}
return HttpxResponse.json(req.conn, StatusOK(), {"message": {"uuid": user.uuid, "expand": user.expand}})
microhttpx is not a complete replacement for full-fledged server frameworks (Flask, FastAPI, etc.)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file microhttpx-0.3.1-py3-none-any.whl.
File metadata
- Download URL: microhttpx-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5e278bb5483ac0b2d63057aa571dcad67c42d7260d530980c75e6c6798459bd
|
|
| MD5 |
dff73dff071aed6747731fbc8590f369
|
|
| BLAKE2b-256 |
86b74cccbee0cbe2d4630021c8f792243a7b1b8e6c6ade173cbe8e3d127dfd8d
|