Module saphir::controller[][src]

Controllers are responsible for handling requests and returning responses to the client.

More specifically a Controller defines a list of endpoint (Handlers) that handle a request and return a Future of a Responder. The [Responder](../ responder/trait.Responder.html) is responsible for the [Response](../ response/struct.Response.html) being generated

To create a controller, simply implement the Controller trait on a struct:

use saphir::prelude::*;

struct BasicController;

impl Controller for BasicController {
    const BASE_PATH: &'static str = "/basic";

    fn handlers(&self) -> Vec<ControllerEndpoint<Self>>
    where
        Self: Sized {
        EndpointsBuilder::new()
            .add(Method::GET, "/healthz", BasicController::healthz)
            .build()
    }
}

impl BasicController {
    async fn healthz(&self, req: Request<Body>) -> impl Responder {200}
}

Structs

EndpointsBuilder

Builder to simplify returning a list of endpoint in the handlers method of the controller trait

Traits

Controller

Trait that defines how a controller handles its requests

ControllerHandler

Trait that defines a handler within a controller. This trait is not meant to be implemented manually as there is a blanket implementation for Async Fns

DynControllerHandler

Type Definitions

ControllerEndpoint

Type definition to represent a endpoint within a controller