[][src]Struct azure_functions::bindings::HttpResponse

pub struct HttpResponse { /* fields omitted */ }

Represents a HTTP output binding.

The following binding attributes are supported:

NameDescription
nameThe name of the parameter being bound.

Responses can be created for any type that implements Into<Body>.

Examples

Creating a response from a string:

use azure_functions::bindings::{HttpRequest, HttpResponse};
use azure_functions::func;

#[func]
pub fn example(_req: HttpRequest) -> HttpResponse {
    "Hello world!".into()
}

Creating a response from a JSON value (see the json! macro from the serde_json crate):

use azure_functions::bindings::{HttpRequest, HttpResponse};
use azure_functions::func;
use serde_json::json;

#[func]
pub fn example(_req: HttpRequest) -> HttpResponse {
    json!({ "hello": "world" }).into()
}

Creating a response from a sequence of bytes:

use azure_functions::bindings::{HttpRequest, HttpResponse};
use azure_functions::func;

#[func]
pub fn example(_req: HttpRequest) -> HttpResponse {
    [1, 2, 3][..].into()
}

Building a custom response:

use azure_functions::bindings::{HttpRequest, HttpResponse};
use azure_functions::func;
use azure_functions::http::Status;

#[func]
pub fn example(_req: HttpRequest) -> HttpResponse {
    HttpResponse::build()
        .status(Status::MovedPermanently)
        .header("Location", "http://example.com")
        .body("The requested resource has moved to: http://example.com")
        .finish()
}

Methods

impl HttpResponse[src]

pub fn build() -> ResponseBuilder[src]

Creates a new ResponseBuilder for building a response.

Examples

use azure_functions::http::Status;

let response = HttpResponse::build().status(Status::NotFound).finish();
assert_eq!(response.status(), Status::NotFound);

pub fn status(&self) -> Status[src]

Gets the status code for the response.

Examples

use azure_functions::http::Status;

let response = HttpResponse::build().status(Status::BadRequest).finish();
assert_eq!(response.status(), Status::BadRequest);

pub fn body(&self) -> Body[src]

Gets the body of the response.

Examples

let response = HttpResponse::build().body("example").finish();

assert_eq!(response.body().as_str().unwrap(), "example");

pub fn headers(&self) -> &HashMap<String, String>[src]

Gets the headers of the response.

Examples

let response = HttpResponse::build().header("Content-Type", "text/plain").finish();

assert_eq!(response.headers().get("Content-Type").unwrap(), "text/plain");

Trait Implementations

impl<'a, T> From<T> for HttpResponse where
    T: Into<Body<'a>>, 
[src]

impl Default for HttpResponse[src]

impl Debug for HttpResponse[src]

Auto Trait Implementations

Blanket Implementations

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

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

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<T> Borrow<T> for T where
    T: ?Sized
[src]

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

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

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

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