Module splinter::rest_api[][src]

Expand description

Rest API Module.

Module for creating REST APIs for services.

Below is an example of a struct that implements ResouceProvider and then passes its resources to a running instance of RestApi.

use actix_web::HttpResponse;
use cylinder::{VerifierFactory, secp256k1::Secp256k1Context};
use futures::IntoFuture;
use splinter::rest_api::{
    AuthConfig, Resource, Method, RestApiBuilder, RestResourceProvider,
    auth::authorization::Permission,
};

struct IndexResource {
    pub name: String
}

impl RestResourceProvider for IndexResource {
    fn resources(&self) -> Vec<Resource> {
        let name = self.name.clone();

        vec![Resource::build("/index").add_method(
            Method::Get,
            Permission::AllowUnauthenticated,
            move |r, p| {
                Box::new(
                    HttpResponse::Ok()
                    .body(format!("Hello, I am {}", name))
                    .into_future())
            },
        )]
    }
}

let index_resource = IndexResource { name: "Taco".to_string() };

#[cfg(not(feature = "https-bind"))]
let bind = "localhost:8080";
#[cfg(feature = "https-bind")]
let bind = splinter::rest_api::BindConfig::Http("localhost:8080".into());

RestApiBuilder::new()
    .add_resources(index_resource.resources())
    .with_bind(bind)
    .with_auth_configs(vec![AuthConfig::Cylinder{
        verifier: Secp256k1Context::new().new_verifier(),
    }])
    .build()
    .unwrap()
    .run();

Modules

Actix Web 3 implementation of the Splinter REST API.

Authentication and authorization for Splinter

Provides CORS support for the REST API

Provides an API for managing secrets

Provides an API for managing user sessions, including issuing and validating JWT tokens

Structs

Model for a error response to an REST request

Guards requests based on a minimum protocol version.

Resource represents a RESTful endpoint.

RestApi is used to create an instance of a restful web server.

Builder struct for RestApi.

Shutdown handle returned by RestApi::run. Allows rest api instance to be shut down gracefully.

Enums

Configurations for the various authentication methods supported by the Splinter REST API.

Bind configuration for the REST API.

A continuation indicates whether or not a guard should allow a given request to continue, or to return a result.

Rest methods compatible with RestApi.

OAuth configurations that are supported out-of-the-box by the Splinter REST API.

Error module for rest_api.

Traits

A guard checks the request content in advance, and either continues the request, or returns a terminating result.

A RestResourceProvider provides a list of resources that are consumed by RestApi.

Functions

Type Definitions