Inside the folder create the __init__.py and the endpoint file
A descriptive name works the best
On the endpoint file
Special attention to APIRouter
from fastapi import APIRouter, Body from fastapi.requests import Request
The prefix indicates the prefix of the endpoint
All endpoint have the same base path, /es/api/v1, from here we attach the prefix, in this case being /Simple, so /es/api/v1/Simple
router = APIRouter(prefix='/Simple', tags=['Simple'])
If you want more information on how to build routes, and what features are available please go to the FastAPI tutorial, whenever you see @app, just replace that with @router
@router.post('/post') async def post_request(req: Request, body: dict = Body()): return body @router.post('/put/{name}') async def post_request(req: Request, name: str): return {"name": name} @router.post('/get/{id}') async def post_request(req: Request, id: int, param_a: int = 0): return f'GET Request for id {id}, with number {param_a}'
In this scenario the path for each route is:
/es/api/v1/Simple/post
/es/api/v1/Simple/put/lincon
/es/api/v1/Simple/get/42
on the __init__ file
If you don’t import the router in the __init__.py, Search API won’t load it
from .simple import router
You can go to /es/docs or /es/redoc and check the
API documentation
Swagger (/es/docs)
ReDoc (/es/redoc)