[−][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") .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]
T: Into<Body<'a>>,
impl Default for HttpResponse
[src]
fn default() -> HttpResponse
[src]
impl Debug for HttpResponse
[src]
Auto Trait Implementations
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnwindSafe for HttpResponse
impl RefUnwindSafe for HttpResponse
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
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> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> IntoRequest<T> for T
[src]
fn into_request(self) -> Request<T>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,