Struct direkuta::Router

source ·
pub struct Router { /* private fields */ }
Expand description

Router.

This is not to be used directly, it is only used for Direkuta.route.

All examples for routing are shown with ‘output’ or what the paths will look like and what the response would look like when called.

The format is as shown.

URL : { Parameter => Capture } {
    Method => Response
}

Implementations§

Adds route to routing map.

Its easier to the the helper functions.

Examples
Simple
Direkuta::new()
    .route(|r| {
        r.route(Method::GET, "/", |_, _, _| {
            Response::new().with_body("Hello World!").build()
        });
    });
"/" {
    GET => "Hello World!"
}
Regex
Direkuta::new()
    .route(|r| {
        r.route(Method::GET, "/<name:(.*)>", |_, _, c| {
            Response::new().with_body(c.get("name")).build()
        });
    });
"/txuritan" : { "name" => "txuritan" } {
    GET => "txuritan"
}

Adds a GET request handler.

Examples
Simple
Direkuta::new()
    .route(|r| {
        r.get("/", |_, _, _| {
            Response::new().with_body("Hello World!").build()
        });
    });
"/" : {  } {
    GET => "Hello World!"
}
Regex
Direkuta::new()
    .route(|r| {
        r.route(Method::GET, "/<name:(.*)>", |_, _, c| {
            Response::new().with_body(c.get("name")).build()
        });
    });
"/txuritan" : { "name" => "txuritan" } {
    GET => "txuritan"
}

Adds a POST request handler.

Examples
Simple
Direkuta::new()
    .route(|r| {
        r.post("/", |_, _, _| {
            Response::new().with_body("Hello World!").build()
        });
    });
"/" : {  } {
    POST => "Hello World!"
}

Adds a PUT request handler.

Examples
Simple
Direkuta::new()
    .route(|r| {
        r.put("/", |_, _, _| {
            Response::new().with_body("Hello World!").build()
        });
    });
"/" : {  } {
    PUT => "Hello World!"
}

Adds a DELETE request handler.

Examples
Simple
Direkuta::new()
    .route(|r| {
        r.delete("/", |_, _, _| {
            Response::new().with_body("Hello World!").build()
        });
    });
"/" : {  } {
    DELETE => "Hello World!"
}

Adds a HEAD request handler.

Examples
Simple
Direkuta::new()
    .route(|r| {
        r.head("/", |_, _, _| {
            Response::new().with_body("Hello World!").build()
        });
    });
"/" : {  } {
    HEAD => "Hello World!"
}

Adds a OPTIONS request handler.

Examples
Simple
Direkuta::new()
    .route(|r| {
        r.options("/", |_, _, _| {
            Response::new().with_body("Hello World!").build()
        });
    });
"/" : {  } {
    OPTIONS => "Hello World!"
}

Create a path for multiple request types.

Examples
Simple
Direkuta::new()
    .route(|r| {
        r.path("/parent", |r| {
            r.get("/child", |_, _, _| {
                Response::new().with_body("Hello World!").build()
            });
        });
    });
"/parent/child" : {  } {
    GET => "Hello World!"
}

Trait Implementations§

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.