API Idempotent requests
Project description
fastapi-idempotent
How to use package fastapi-idempotent
# Install package using poetry
poetry add fastapi-idempotent
# Using pip
pip install fastapi-idempotent
Set rate limit for FastAPI before starting server
Example code
- main.py
# Import package
from fastapi import FastAPI
from fastapi_idempotent import IdempotentMiddleWare
from core.config import settings # settings is class, where the configuration parameters are saved
from api.responses import JSONResponse
...
# Setup FastAPI
app = FastAPI(
title=settings.PROJECT_NAME,
version=settings.API_VERSION,
openapi_url=f"{settings.API_V1_PATH}/openapi.json",
default_response_class=JSONResponse,
)
Set idempotent for FastAPI
- Using redis storage
# Default idempotent expired is 10800s
app.add_middleware(
IdempotentMiddleWare,
redis_url=settings.IDEMPOTENT_STORAGE_URL, # type: str
)
or
app.add_middleware(
IdempotentMiddleWare,
idempotent_expired=settings.IDEMPOTENT_EXPIRED, # type: int
redis_url=settings.IDEMPOTENT_STORAGE_URL, # type: str
)
- Using memory storage
# Default idempotent expired is 10800s
app.add_middleware(
IdempotentMiddleWare,
testing=True, # type: bool
)
or
app.add_middleware(
IdempotentMiddleWare,
idempotent_expired=settings.IDEMPOTENT_EXPIRED, # type: int
testing=True, # type: bool
)
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_idempotent-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a71469df0f2aa436599cc4389e48e006a34209f37f6b6d1310bcf55c1f48e16 |
|
MD5 | 5850657ff7cfaf3aa0130599a5ad57da |
|
BLAKE2b-256 | c739e0431a5092d40337d0c761578c9a7d31085739161d7c9ff9f108ee79e102 |