[][src]Trait replicante_util_iron::RootDescriptor

pub trait RootDescriptor {
    fn enabled(&self, flags: &HashMap<&'static str, bool>) -> bool;
fn prefix(&self) -> &'static str; fn trace(&self) -> bool { ... } }

Interface for types that describe endpoint roots.

Useful to codify in a sensible way which possible paths are exposed by an API.

Example

use replicante_util_iron::RootDescriptor;

enum APIVersion {
    V1,
    V2,
    V3,
}

impl RootDescriptor for APIVersion {
    fn enabled(&self, flags: &HashMap<&'static str, bool>) -> bool {
        match self {
            APIVersion::V1 => match flags.get("v1") {
                Some(flag) => *flag,
                None => match flags.get("legacy") {
                    Some(flag) => *flag,
                    None => true,
                },
            },
            APIVersion::V2 => match flags.get("v2") {
                Some(flag) => *flag,
                None => match flags.get("legacy") {
                    Some(flag) => *flag,
                    None => true,
                },
            },
            APIVersion::V3 => true,
        }
    }

    fn prefix(&self) -> &'static str {
        match self {
            APIVersion::V1 => "/api/v1",
            APIVersion::V2 => "/some/other/path",
            APIVersion::V3 => "/v3",
        }
    }
}

Required methods

fn enabled(&self, flags: &HashMap<&'static str, bool>) -> bool

Check if a root should be enabled according to the given flags.

fn prefix(&self) -> &'static str

Return the URI prefix for a root.

Loading content...

Provided methods

fn trace(&self) -> bool

Trace requests to a root, if tracing is enabled.

Tracing of roots is on by default but can be turned off for low-value and high-rate roots (like introspection or debugging) by returning false.

Loading content...

Implementors

Loading content...