[][src]Struct splinter::rest_api::Resource

pub struct Resource { /* fields omitted */ }

Resource represents a RESTful endpoint.

use splinter::rest_api::{Resource, Method};
use actix_web::HttpResponse;
use futures::IntoFuture;

Resource::build("/index")
    .add_method(Method::Get, |r, p| {
        Box::new(
            HttpResponse::Ok()
                .body("Hello, World")
                .into_future()
        )
    });

Methods

impl Resource[src]

pub fn new<F>(method: Method, route: &str, handle: F) -> Self where
    F: Fn(HttpRequest, Payload) -> Box<dyn Future<Item = HttpResponse, Error = ActixError>> + Send + Sync + 'static, 
[src]

Deprecated:

Please use the build and add_method methods instead

pub fn build(route: &str) -> Self[src]

pub fn add_method<F>(self, method: Method, handle: F) -> Self where
    F: Fn(HttpRequest, Payload) -> Box<dyn Future<Item = HttpResponse, Error = ActixError>> + Send + Sync + 'static, 
[src]

pub fn add_request_guard<RG>(self, guard: RG) -> Self where
    RG: RequestGuard + Clone + 'static, 
[src]

Adds a RequestGuard to the given Resource.

This guard applies to all methods defined for this resource.

Example

use splinter::rest_api::{Resource, Method, Continuation};
use actix_web::{HttpRequest, HttpResponse};
use futures::IntoFuture;

Resource::build("/index")
    .add_request_guard(|r: &HttpRequest| {
        if !r.headers().contains_key("GuardFlag") {
            Continuation::terminate(
                HttpResponse::BadRequest().finish().into_future(),
            )
        } else {
            Continuation::Continue
        }
    })
    .add_method(Method::Get, |r, p| {
        Box::new(
            HttpResponse::Ok()
                .body("Hello, World")
                .into_future()
        )
    });

Trait Implementations

impl Clone for Resource[src]

Auto Trait Implementations

impl !RefUnwindSafe for Resource

impl Send for Resource

impl Sync for Resource

impl Unpin for Resource

impl !UnwindSafe for Resource

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<'a, T> DefaultFeatures<'a> for T where
    T: 'a + Clone + Send + Sync

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoSql for T

impl<'a, T> NonSyncFeatures<'a> for T where
    T: 'a + Clone

impl<T> SafeBorrow<T> for T where
    T: ?Sized

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,