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 splinter::rest_api::{Resource, Method, RestApiBuilder, RestResourceProvider};
use actix_web::HttpResponse;
use futures::IntoFuture;
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, move |r, p| {
Box::new(
HttpResponse::Ok()
.body(format!("Hello, I am {}", name))
.into_future())
})]
}
}
let index_resource = IndexResource { name: "Taco".to_string() };
RestApiBuilder::new()
.add_resources(index_resource.resources())
.with_bind("localhost:8080")
.build()
.unwrap()
.run();
Modules
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
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
.
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
.