[][src]Crate direkuta

A web framework built around Hyper.

Examples

Please note that none of these are tested due to Direkuta being a web sever.

If, for some reason, they don't work, have a look at the examples folder.

Simple

This example is not tested
use direkuta::prelude::*;

Direkuta::new()
    .route(|r| {
        r.get("/", |_, _, _| {
            Response::new().with_body("Hello World!").build()
        });
    })
    .run("0.0.0.0:3000");

Tera Templates

This example is not tested
extern crate direkuta;

use direkuta::prelude::*;sp
use direkuta::prelude::html::*;

fn main() {
    Direkuta::new()
        .route(|r| {
            r.get("/", |_, s, _| {
                Response::new().with_body(s
                    .get::<Tera>()
                    .render(Context::new(), "index.html")
                    .unwrap()).build()
            });
        }).run("0.0.0.0:3000");
}

JSON

This example is not tested
extern crate direkuta;
#[macro_use]
extern crate serde_derive;

use direkuta::prelude::*;

#[derive(Serialize)]
struct Example {
    hello: String,
}

fn main() {
    Direkuta::new()
        .route(|r| {
            r.get("/", |_, _, _| {
                Response::new().with_json(|j| {
                    j.body(Example {
                        hello: String::from("world"),
                    });
                }).build()
            });
        }).run("0.0.0.0:3000");
}

Routing

This example is not tested
extern crate direkuta;

use direkuta::prelude::*;

fn main() {
    Direkuta::new()
        .route(|r| {
            r.get("/<name:(.+)>", |_, _, c| {
                Response::new().with_body(c.get("name")).build()
            });
        }).run("0.0.0.0:3000");
}

Modules

prelude

Imports just the required parts of Direkuta.

Macros

headermap

Creates a HeaderMap from a list of key-value pairs.

Structs

Capture

A wrapper around IndexMap<String, String>.

Config

Internal configuration for the server.

CssBuilder

A builder function for CSS Responses.

Direkuta

The Direkuta web server itself.

JsBuilder

A builder function for JS Responses.

JsonBuilder

A builder for JSON responses.

Logger

A simple logger middleware.

Request

A wrapper around Hyper Request.

Response

A wrapper around Hyper Response.

Router

Router.

State

A wrapper around IndexMap<TypeId, Any>, used to store server state.

Enums

DireError

Wrapper around common and library error types.

Traits

Middle

All middleware must implement this trait.