Skip to main content

FastAPI middleware for mocking response data of non-implemented endpoints

Project description

FastAPI mock middleware

license pypi test codecov

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


Download files

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

Source Distribution

fastapi_mock_middleware-0.1.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

fastapi_mock_middleware-0.1.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_mock_middleware-0.1.1.tar.gz.

File metadata

File hashes

Hashes for fastapi_mock_middleware-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d2a6ccc07a5a8c89891be3bb2542f57de62fb7312da8bf6093bac634ac7a521d
MD5 f4c106a5bbab9029a0abb09b930e3249
BLAKE2b-256 b6c69beaabff0c87aa69639039e57b89be80f15fbdd98e560f136319b8039c3f

See more details on using hashes here.

File details

Details for the file fastapi_mock_middleware-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_mock_middleware-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49534fd91a7f3cc24a0a8352bb09ea505e7465b6227dfdd499dcd77e3c4cadd6
MD5 7cf8fd33e230f7937677693f3039a92d
BLAKE2b-256 64a21ab423724066e13fb5048762c56125adf5adc8d9f90b8d5635aaec8237c1

See more details on using hashes here.

Supported by

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