pub struct HttpResponse { /* private fields */ }
Expand description
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()
}
Implementations§
Source§impl HttpResponse
impl HttpResponse
Sourcepub fn build() -> ResponseBuilder
pub fn build() -> ResponseBuilder
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);
Sourcepub fn status(&self) -> Status
pub fn status(&self) -> Status
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);
Trait Implementations§
Source§impl Debug for HttpResponse
impl Debug for HttpResponse
Source§impl Default for HttpResponse
impl Default for HttpResponse
Source§fn default() -> HttpResponse
fn default() -> HttpResponse
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for HttpResponse
impl RefUnwindSafe for HttpResponse
impl Send for HttpResponse
impl Sync for HttpResponse
impl Unpin for HttpResponse
impl UnwindSafe for HttpResponse
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request