Skip to main content

Middleware for validating basic JSON-RPC requests

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_middleware_jsonrpc


Swarmauri Middleware JsonRpc

Middleware that performs simple validation of JSON-RPC requests.

Features

  • Validates JSON request bodies for JSON-RPC payloads when the Content-Type header starts with application/json.
  • Returns 400 Bad Request with a plain-text error when the body contains invalid JSON.
  • Ensures JSON object payloads define a jsonrpc field, responding with 400 Bad Request if 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/json content type bypass the middleware.
  • Malformed JSON bodies are rejected with a 400 response containing the message Invalid JSON.
  • JSON objects missing the jsonrpc key are rejected with a 400 response and the message Missing 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_middleware_jsonrpc-0.8.0.dev44.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_middleware_jsonrpc-0.8.0.dev44.tar.gz.

File metadata

  • Download URL: swarmauri_middleware_jsonrpc-0.8.0.dev44.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

Hashes for swarmauri_middleware_jsonrpc-0.8.0.dev44.tar.gz
Algorithm Hash digest
SHA256 4a97c0b6743b8aac53a98c6af03e034b2ff6b408ee06791d54fbd70f37ab0646
MD5 2a019fc1866d48054928e0f32b614feb
BLAKE2b-256 1886d3b73f4858bdfa9b76a2bb9164d210ab52785d652b643a093c074add2b01

See more details on using hashes here.

File details

Details for the file swarmauri_middleware_jsonrpc-0.8.0.dev44-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_middleware_jsonrpc-0.8.0.dev44-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

Hashes for swarmauri_middleware_jsonrpc-0.8.0.dev44-py3-none-any.whl
Algorithm Hash digest
SHA256 0898a0cab786bc72c43803ee2b09593005ff3e760e71c8e7e5e5dff5b7a70de9
MD5 8ed5ebda5c7d8095650c5c72728697e3
BLAKE2b-256 224ba623bf5acfb55b9639789600e66a955a34e7724481aeb344e6f71cd1f865

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page