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_1 | |
actix_web_3 | Actix Web 3 implementation of the Splinter REST API. |
auth | Authentication and authorization for Splinter |
cors | Provides CORS support for the REST API |
paging | |
secrets | Provides an API for managing secrets |
sessions | Provides an API for managing user sessions, including issuing and validating JWT tokens |
Structs
ErrorResponse | Model for a error response to an REST request |
EventSender | |
ProtocolVersionRangeGuard | Guards requests based on a minimum protocol version. |
Request | |
Resource |
|
Response | |
RestApi |
|
RestApiBuilder | Builder |
RestApiShutdownHandle | Shutdown handle returned by |
Enums
AuthConfig | Configurations for the various authentication methods supported by the Splinter REST API. |
BindConfig | Bind configuration for the REST API. |
Continuation | A continuation indicates whether or not a guard should allow a given request to continue, or to return a result. |
Method | Rest methods compatible with |
OAuthConfig | OAuth configurations that are supported out-of-the-box by the Splinter REST API. |
RequestError | |
ResponseError | |
RestApiServerError | Error module for |
Traits
RequestGuard | A guard checks the request content in advance, and either continues the request, or returns a terminating result. |
RestResourceProvider | A |
Functions
get_authorization_token | |
into_bytes | |
into_protobuf | |
new_websocket_event_sender | |
percent_encode_filter_query | |
require_header |
Type Definitions
HandlerFunction |