[−][src]Struct azure_functions::bindings::HttpResponse
Represents a HTTP output binding.
The following binding attributes are supported:
| Name | Description |
|---|---|
name | The 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") .into() }
Methods
impl HttpResponse[src]
pub fn build() -> ResponseBuilder[src]
Creates a new ResponseBuilder for building a response.
Examples
use azure_functions::bindings::HttpResponse; use azure_functions::http::Status; let response: HttpResponse = HttpResponse::build().status(Status::NotFound).into(); assert_eq!(response.status(), Status::NotFound);
pub fn status(&self) -> Status[src]
Gets the status code for the response.
Examples
use azure_functions::bindings::HttpResponse; use azure_functions::http::Status; let response: HttpResponse = HttpResponse::build().status(Status::BadRequest).into(); assert_eq!(response.status(), Status::BadRequest);
pub fn body(&self) -> Body[src]
Gets the body of the response.
Examples
use azure_functions::bindings::HttpResponse; let response: HttpResponse = HttpResponse::build().body("example").into(); assert_eq!(response.body().as_str().unwrap(), "example");
pub fn headers(&self) -> &HashMap<String, String>[src]
Gets the headers of the response.
Examples
use azure_functions::bindings::HttpResponse; let response: HttpResponse = HttpResponse::build().header("Content-Type", "text/plain").into(); assert_eq!(response.headers().get("Content-Type").unwrap(), "text/plain");
Trait Implementations
impl Default for HttpResponse[src]
fn default() -> HttpResponse[src]
impl<'a, T> From<T> for HttpResponse where
T: Into<Body<'a>>, [src]
T: Into<Body<'a>>,
impl From<ResponseBuilder> for HttpResponse[src]
fn from(builder: ResponseBuilder) -> Self[src]
impl Debug for HttpResponse[src]
Auto Trait Implementations
impl Send for HttpResponse
impl Sync for HttpResponse
Blanket Implementations
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,