Routes

Implement your application logic using standard FastAPI routes(opens in new tab). LongLink provides the current user and common services such as the database and storage through Context, so you can use them directly without additional configuration.

Example

main.py — python
from longlink import Context, LongLink
​
​
app = LongLink()
​
​
@app.get("/api/me", response_model=str)
async def current_user_name(ctx: Context) -> str:
"""Return the current user's name."""
​
# Read the user supplied by LongLink for this request.
return ctx.user.name

Permissions

LongLink discovers permissions from registered HTTP methods and path templates at build time and stores the catalog in the container image alongside environment requirements. No operation ID or separate configuration file is needed. GET, HEAD, and OPTIONS default to the read and write roles; POST, PUT, PATCH, and DELETE default to write. These are conventions: declare explicit roles for sensitive reads, approvals, and other operations that need different access.

Register all business routes when importing main:app, without requiring runtime configuration or starting services. Route methods, paths, summaries, and roles must be deterministic and must not depend on environment values or lifespan hooks. Builds compare catalogs from two isolated imports; the runtime rejects requests whose permission catalog differs from the image metadata.

python
from longlink import APIRouter
​
router = APIRouter(prefix="/api/invoices")
​
@router.post("/{id}/approve", roles=["admin"])
async def approve_invoice(id: int) -> dict[str, int]:
return {"approved": id}

Import APIRouter from longlink to use the roles keyword on route decorators. It also works directly on LongLink applications. Explicit roles replace method defaults; pass role names as a list, or an empty list for no role defaults. Role names are lowercase identifiers, and Solution admin is not a Platform administrator or an automatic bypass. Endpoints excluded from OpenAPI are still protected. Custom mounts are not supported for business operations.

Build and deploy the image, then open Permissions in the Solution actions under organization settings. Assign each member one of the SDK-defined roles, or select No access to set their role to null and disable Solution access. Individual endpoint permissions are read-only in the Platform and come exclusively from the role declarations in your Solution. Unassigned members have no Solution access, and Write includes DELETE. Endpoint permissions are enforced for every deployed Solution.

Deployments update role definitions without changing member role assignments. A changed method or path is a new permission. Failed deployments and recovery retain the appropriate revision defaults. MCP agents act as their authorizing user and use that user's current Solution permissions, including subsequent permission changes.

Permissions are enforced before endpoint dependencies and handlers, including calls made through MCP. They control operations, not individual records or fields; keep business-level checks in the endpoint when access depends on an invoice's owner or state. Local development keeps the seeded development identity and does not require Platform assignments.

Exceptions

Invalid input returns 422. Unhandled exceptions return a generic 500 response without exposing the original message. Raise HTTPException to return a status code and a public error message:

python
from fastapi import HTTPException
​
​
raise HTTPException(status_code=404, detail="Project not found")