Middleware for validating basic JSON-RPC requests
Project description
Swarmauri Middleware JsonRpc
Middleware that performs simple validation of JSON-RPC requests.
Features
- Validates JSON request bodies for JSON-RPC payloads when the
Content-Typeheader starts withapplication/json. - Returns
400 Bad Requestwith a plain-text error when the body contains invalid JSON. - Ensures JSON object payloads define a
jsonrpcfield, responding with400 Bad Requestif it is missing.
Installation
Install the middleware with your preferred Python packaging workflow:
pip install swarmauri_middleware_jsonrpc
poetry add swarmauri_middleware_jsonrpc
uv add swarmauri_middleware_jsonrpc
uv pip install swarmauri_middleware_jsonrpc
Usage
from fastapi import FastAPI
from swarmauri_middleware_jsonrpc import JsonRpcMiddleware
app = FastAPI()
app.middleware("http")(JsonRpcMiddleware().dispatch)
The middleware integrates with FastAPI's app.middleware("http") hook and is
compatible with the MiddlewareBase ecosystem. Once registered, every incoming
JSON request is validated before reaching subsequent middleware or route
handlers.
Request Validation
- Requests without an
application/jsoncontent type bypass the middleware. - Malformed JSON bodies are rejected with a
400response containing the messageInvalid JSON. - JSON objects missing the
jsonrpckey are rejected with a400response and the messageMissing jsonrpc field.
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
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 Distribution
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 swarmauri_middleware_jsonrpc-0.8.0.dev47.tar.gz.
File metadata
- Download URL: swarmauri_middleware_jsonrpc-0.8.0.dev47.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
769b96843baab85bdaea2efc74be07cae4fa14f36261ef0c3146f094c4244efd
|
|
| MD5 |
2b1bd5a5147e6a4cac95922a9c01c7f5
|
|
| BLAKE2b-256 |
da054a5164c7426bf98e343831928f9656379519596baa7164923e613a5baff9
|
File details
Details for the file swarmauri_middleware_jsonrpc-0.8.0.dev47-py3-none-any.whl.
File metadata
- Download URL: swarmauri_middleware_jsonrpc-0.8.0.dev47-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
184c844c5629d0fa121038d6dce618807bbbbf23d3facb06f0823bb9a22f0ad7
|
|
| MD5 |
fef59434654fd86747444910d15c1ad1
|
|
| BLAKE2b-256 |
d4801a8256cc0935460c44a5b24554a41db00da7350856b869c948d06ad4f0bf
|