FastAPI middleware for mocking response data of non-implemented endpoints
Project description
FastAPI mock middleware
FastAPI middleware for mocking response data of non-implemented endpoints.
Mock data is generated in accordance with endpoint return type or provided response_model using polifactory.
For more information on how to use fastapi-mock-middleware, please refer to the official documentation.
Installation
pip install fastapi-mock-middleware
Usage example
Add MockAPIMiddleware
middleware to app and raise APINotImplementedError
in
your endpoint stubs.
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi_mock_middleware import MockAPIMiddleware, APINotImplementedError
app = FastAPI()
app.add_middleware(MockAPIMiddleware)
class Item(BaseModel):
id: int
name: str
@app.get('/')
async def list_items() -> list[Item]:
raise APINotImplementedError()
if __name__ == '__main__':
uvicorn.run('example:app', reload=True)
Check the response using curl
.
curl http://127.0.0.1:8000/
Called API must return mocked data:
[
{
"id": 5392,
"name": "gVzyVVUmGGevXlQvXGBW"
}
]
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
Close
Hashes for fastapi-mock-middleware-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea96a96f4b991b79661ef5f6139f8a4b5460fd84dfde3e9b23a9457be84c2e56 |
|
MD5 | 0a4c99e50640089b9a629919aaabf49c |
|
BLAKE2b-256 | 42afa94364f697148355fbae6f9577854964c52036533c644b5c0c9e8d72a24d |
Close
Hashes for fastapi_mock_middleware-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1455285de550ac3c594915f994166f374825783ca390f183a0c7739d9a50a2e1 |
|
MD5 | 3f74a6ebcc1694ae811c954b81992ab5 |
|
BLAKE2b-256 | c8fe94a9dbe4fa5ab514697b6a6fa6e6fe2c59d644c5c66d597cc57cb395b0bd |