Metadata-Version: 2.4
Name: swarmauri_middleware_jsonrpc
Version: 0.11.0.dev1
Summary: Middleware for validating basic JSON-RPC requests
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: swarmauri,sdk,standards,middleware,jsonrpc
Author: Jacob Stewart
Author-email: jacob@swarmauri.com
Requires-Python: >=3.10,<3.15
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: fastapi
Requires-Dist: swarmauri_base
Requires-Dist: swarmauri_core
Requires-Dist: swarmauri_standard
Description-Content-Type: text/markdown

![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)

<p align="center">
    <a href="https://pepy.tech/project/swarmauri_middleware_jsonrpc/">
        <img src="https://static.pepy.tech/badge/swarmauri_middleware_jsonrpc/month" alt="PyPI - Downloads"/></a>
    <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_jsonrpc/">
        <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_jsonrpc.svg"/></a>
    <a href="https://pypi.org/project/swarmauri_middleware_jsonrpc/">
        <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
    <a href="https://pypi.org/project/swarmauri_middleware_jsonrpc/">
        <img src="https://img.shields.io/pypi/l/swarmauri_middleware_jsonrpc" alt="PyPI - License"/></a>
    <a href="https://pypi.org/project/swarmauri_middleware_jsonrpc/">
        <img src="https://img.shields.io/pypi/v/swarmauri_middleware_jsonrpc?label=swarmauri_middleware_jsonrpc&color=green" alt="PyPI - swarmauri_middleware_jsonrpc"/></a>
    <a href="https://discord.gg/N4UpBuQv8T">
        <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>

# 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:

```bash
pip install swarmauri_middleware_jsonrpc
```

```bash
poetry add swarmauri_middleware_jsonrpc
```

```bash
uv add swarmauri_middleware_jsonrpc
```

```bash
uv pip install swarmauri_middleware_jsonrpc
```

## Usage

```python
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](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
that will help you get started.


