If you are new to GAIA API and want to add an endpoint we recommend you start with How to Add and API Endpoint

The API framework is entirely based on FastAPI, and it simplifies just where and how you can add new endpoints to GAIA API. Besides that everything is FastAPI, but using a router instead of the application directly since using routers give us the following advantages:

  1. Modular code organization: Routers help organize code into separate modules, making it easier to manage and maintain larger API codebases.

  2. Route prefixing: Routers allow you to group related routes together using a common prefix, providing a clean and intuitive structure for API endpoints.

  3. Dependency injection: Routers support dependency injection, allowing you to declare and reuse dependencies at the router level.

  4. Sub-applications: Routers enable the creation of sub-applications within the main FastAPI app, facilitating the development and maintenance of complex APIs.

  5. Route inheritance and overrides: Routers support route inheritance, allowing you to define common behavior and middleware at the router level, with the ability to override specific routes when needed.

As you can see each router, in GAIA API is an endpoint, and within that endpoint you can do whatever you want.

Read about Routers

If you want to know more about routers and the guidelines we used for GAIA API visit the FastAPI documentation about Bigger Applications - Multiple Files

Security covers all endpoints

If security is enabled, by default all endpoints are cover by it, if by any change 

Routes With App


from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Hello, World!"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

Routes With Router


from fastapi import APIRouter

router = APIRouter()

@router.get("/")
def read_root():
    return {"message": "Hello, World!"}

@router.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

Same in both examples but in the end, the router must be included in the app

from fastapi import FastAPI
from myrouter import router

app = FastAPI()

app.include_router(router)

Made simple

GAIA API already does this for you, only the implementation of the routes in the router is required 


Endpoints Available Add endpoint


  • No labels