Sign in

    moonbitstack/moonapi/route does not have a README file

    ApiHandler

    A route handler (← a FastAPI path operation): the request context in, a response out. It runs async, so it can await a database or another service; a plain closure is one too, and a named function that is not async is registered as ctx => f(ctx). It may raise an HttpException (or any error) instead of returning — the app maps it to a response through the registered exception handlers.

    Method

    The request method a route binds to: the nine standard ones and any other token, from moonhttp.

    StreamHandler

    A streaming route's handler (← a FastAPI path operation returning a StreamingResponse): the response it returns writes its body while it is sent.

    Reply

    What a route produced: a response with its body in hand, or one that writes its body as it goes.

    Route

    pub(all) struct Route {
    verb :
    Method

    path : String
    run : async (
    Context
    ) -> Reply
    summary : String
    description : String
    tags : Array[String]
    deprecated : Bool
    operation_id : String
    status_code : Int?
    responses : Array[
    ResponseSpec
    ]
    name : String
    openapi_extra : Json?
    endpoint :
    Endpoint
    ?
    security : Array[
    SecurityRequirement
    ]
    dependencies : Array[String]
    include_in_schema : Bool
    validate : Bool
    }

    One registered route, the record an app keeps for each operation — what FastAPI calls APIRoute. Public so a program can list and inspect an app's routes; building one by hand is possible but the App methods are the way.

    security is the per-operation requirements (emitted as OpenAPI security and enforced before the handler when their scheme has an enforcer).

    Router

    pub struct Router {
    routes : Array[Route]
    ws_routes : Array[
    WsRoute
    ]
    }

    A collection of routes built away from any application and folded into one with App::include_router (← FastAPI's APIRouter). It carries the registration surface of an App and nothing else: middleware, mounts, security schemes, documentation and lifespan belong to the application that includes it.

    Router::delete

    fn Router::delete(self : Router, path : String, handler : async (
    Context
    ) ->
    Response
    , summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, operation_id? : String, status_code? : Int, responses? : Array[
    ResponseSpec
    ], name? : String, endpoint? :
    Endpoint
    , security? : Array[
    SecurityRequirement
    ], dependencies? : Array[String], include_in_schema? : Bool, validate? : Bool, openapi_extra? : Json) -> Unit

    Register a DELETE route on the router.

    Router::get

    fn Router::get(self : Router, path : String, handler : async (
    Context
    ) ->
    Response
    , summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, operation_id? : String, status_code? : Int, responses? : Array[
    ResponseSpec
    ], name? : String, endpoint? :
    Endpoint
    , security? : Array[
    SecurityRequirement
    ], dependencies? : Array[String], include_in_schema? : Bool, validate? : Bool, openapi_extra? : Json) -> Unit

    Register a GET route on the router.

    Router::new

    fn Router::new() -> Router

    An empty router. The prefix and the attributes its routes share are given at App::include_router rather than here, so one router can be included twice — under a second prefix, or on another app with different tags.

    Router::patch

    fn Router::patch(self : Router, path : String, handler : async (
    Context
    ) ->
    Response
    , summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, operation_id? : String, status_code? : Int, responses? : Array[
    ResponseSpec
    ], name? : String, endpoint? :
    Endpoint
    , security? : Array[
    SecurityRequirement
    ], dependencies? : Array[String], include_in_schema? : Bool, validate? : Bool, openapi_extra? : Json) -> Unit

    Register a PATCH route on the router.

    Router::post

    fn Router::post(self : Router, path : String, handler : async (
    Context
    ) ->
    Response
    , summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, operation_id? : String, status_code? : Int, responses? : Array[
    ResponseSpec
    ], name? : String, endpoint? :
    Endpoint
    , security? : Array[
    SecurityRequirement
    ], dependencies? : Array[String], include_in_schema? : Bool, validate? : Bool, openapi_extra? : Json) -> Unit

    Register a POST route on the router.

    Router::put

    fn Router::put(self : Router, path : String, handler : async (
    Context
    ) ->
    Response
    , summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, operation_id? : String, status_code? : Int, responses? : Array[
    ResponseSpec
    ], name? : String, endpoint? :
    Endpoint
    , security? : Array[
    SecurityRequirement
    ], dependencies? : Array[String], include_in_schema? : Bool, validate? : Bool, openapi_extra? : Json) -> Unit

    Register a PUT route on the router.

    Router::route

    fn Router::route(self : Router, verb :
    Method
    , path : String, handler : async (
    Context
    ) ->
    Response
    , summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, operation_id? : String, status_code? : Int, responses? : Array[
    ResponseSpec
    ], name? : String, endpoint? :
    Endpoint
    , security? : Array[
    SecurityRequirement
    ], dependencies? : Array[String], include_in_schema? : Bool, validate? : Bool, openapi_extra? : Json) -> Unit

    Register a route on the router for an explicit method. Takes what App::route takes and means the same by it; the route reaches an application when the router is included.

    Router::route_stream

    fn Router::route_stream(self : Router, verb :
    Method
    , path : String, handler : async (
    Context
    ) ->
    Stream
    , summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, operation_id? : String, status_code? : Int, responses? : Array[
    ResponseSpec
    ], name? : String, endpoint? :
    Endpoint
    , security? : Array[
    SecurityRequirement
    ], dependencies? : Array[String], include_in_schema? : Bool, validate? : Bool, openapi_extra? : Json) -> Unit

    Register a streaming route for an explicit method — App::route_stream, deferred to whichever application includes the router.

    Router::stream

    fn Router::stream(self : Router, path : String, handler : async (
    Context
    ) ->
    Stream
    , summary? : String, description? : String, tags? : Array[String], deprecated? : Bool, operation_id? : String, status_code? : Int, responses? : Array[
    ResponseSpec
    ], name? : String, endpoint? :
    Endpoint
    , security? : Array[
    SecurityRequirement
    ], dependencies? : Array[String], include_in_schema? : Bool, validate? : Bool, openapi_extra? : Json) -> Unit

    Register a streaming GET route on the router, the verb a stream is nearly always read over.

    Router::websocket

    fn Router::websocket(self : Router, path : String, handler : async (
    WebSocket
    ) -> Unit) -> Unit

    Register a WebSocket route on the router (← APIRouter.websocket). It takes the including prefix like any other route; the operation attributes do not apply, since a WebSocket route is not an OpenAPI operation.

    segments

    fn segments(path : String) -> Array[String]

    Split a path into its non-empty segments.

    Source Files