rocket_lamb

Struct RocketHandlerBuilder

Source
pub struct RocketHandlerBuilder { /* private fields */ }
Expand description

A builder to create and configure a RocketHandler.

Implementations§

Source§

impl RocketHandlerBuilder

Source

pub fn new(rocket: Rocket) -> RocketHandlerBuilder

Create a new RocketHandlerBuilder. Alternatively, you can use rocket.lambda().

§Example
use rocket_lamb::RocketHandlerBuilder;

let builder = RocketHandlerBuilder::new(rocket::ignite());
Source

pub fn into_handler(self) -> RocketHandler

Creates a new RocketHandler from an instance of Rocket, which can be passed to the lambda_http::lambda! macro.

Alternatively, you can use the launch() method.

§Example
use rocket_lamb::RocketExt;
use lambda_http::lambda;

let handler = rocket::ignite().lambda().into_handler();
lambda!(handler);
Source

pub fn launch(self) -> !

Starts handling Lambda events by polling for events using Lambda’s Runtime APIs.

This function does not return, as it will loop forever (unless it panics).

§Panics

This panics if the required Lambda runtime environment variables are not set, or if the Rocket used to create the builder was misconfigured.

§Example
use rocket_lamb::RocketExt;
use lambda_http::lambda;

rocket::ignite().lambda().launch();
Examples found in repository?
examples/hello_api.rs (line 16)
12
13
14
15
16
17
fn main() {
    rocket::ignite()
        .mount("/hello", routes![hello])
        .lambda()
        .launch();
}
Source

pub fn get_default_response_type(&self) -> ResponseType

Gets the default ResponseType, which is used for any responses that have not had their Content-Type overriden with response_type.

§Example
use rocket_lamb::{RocketExt, ResponseType};

let builder = rocket::ignite().lambda();
assert_eq!(builder.get_default_response_type(), ResponseType::Auto);
assert_eq!(builder.get_response_type("text/plain"), ResponseType::Auto);
Source

pub fn default_response_type(self, response_type: ResponseType) -> Self

Sets the default ResponseType, which is used for any responses that have not had their Content-Type overriden with response_type.

§Example
use rocket_lamb::{RocketExt, ResponseType};

let builder = rocket::ignite()
    .lambda()
    .default_response_type(ResponseType::Binary);
assert_eq!(builder.get_default_response_type(), ResponseType::Binary);
assert_eq!(builder.get_response_type("text/plain"), ResponseType::Binary);
Source

pub fn get_response_type(&self, content_type: &str) -> ResponseType

Gets the configured ResponseType for responses with the given Content-Type header.

content_type values are treated case-insensitively.

§Example
use rocket_lamb::{RocketExt, ResponseType};

let builder = rocket::ignite()
    .lambda()
    .response_type("TEXT/PLAIN", ResponseType::Text);
assert_eq!(builder.get_response_type("text/plain"), ResponseType::Text);
assert_eq!(builder.get_response_type("application/json"), ResponseType::Auto);
Source

pub fn response_type( self, content_type: &str, response_type: ResponseType, ) -> Self

Sets the ResponseType for responses with the given Content-Type header.

content_type values are treated case-insensitively.

§Example
use rocket_lamb::{RocketExt, ResponseType};

let builder = rocket::ignite()
    .lambda()
    .response_type("TEXT/PLAIN", ResponseType::Text);
assert_eq!(builder.get_response_type("text/plain"), ResponseType::Text);
assert_eq!(builder.get_response_type("application/json"), ResponseType::Auto);
Source

pub fn base_path_behaviour(self, setting: BasePathBehaviour) -> Self

Determines whether the API Gateway base path is included in the URL processed by Rocket. The default is RemountAndInclude.

When calling the API using the default API Gateway URL e.g. {api-id}.execute-api.{region}.amazonaws.com/{stage}/, the base path will be /{stage}. When calling the API using an API Gateway custom domain, a base path may be configured on the custom domain.

This has no effect for Application Load Balancer requests, as these will never have a base path.

The possible values are:

  • RemountAndInclude - Includes the base bath in the URL. The first request received will be used to determine the base path, and all mounted routes will be cloned and re-mounted at the base path.
  • Include - Includes the base bath in the URL. You must ensure that the Rocket’s routes have been mounted at the expected base path.
  • Exclude - Excludes the base bath from the URL. The URL processed by Rocket may not match the full path of the original client, which may cause absolute URLs in responses (e.g. in the Location response header for redirects) to not behave as expected.
§Example
use rocket_lamb::{BasePathBehaviour, RocketExt};

let builder = rocket::ignite()
    .lambda()
    .base_path_behaviour(BasePathBehaviour::Exclude);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, I> AsResult<T, I> for T
where I: Input,

Source§

fn as_result(self) -> Result<T, ParseErr<I>>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoCollection<T> for T

Source§

fn into_collection<A>(self) -> SmallVec<A>
where A: Array<Item = T>,

Converts self into a collection.
Source§

fn mapped<U, F, A>(self, f: F) -> SmallVec<A>
where F: FnMut(T) -> U, A: Array<Item = U>,

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.