pub struct ResponseBuilder(/* private fields */);
Expand description
Represents a builder for HTTP responses.
Implementations§
Source§impl ResponseBuilder
impl ResponseBuilder
Sourcepub fn new() -> ResponseBuilder
pub fn new() -> ResponseBuilder
Creates a new ResponseBuilder
.
Sourcepub fn status<S: Into<Status>>(self, status: S) -> Self
pub fn status<S: Into<Status>>(self, status: S) -> Self
Sets the status for the response.
§Examples
use azure_functions::http::Status;
let response = ResponseBuilder::new()
.status(Status::InternalServerError)
.finish();
assert_eq!(response.status(), Status::InternalServerError);
Sourcepub fn header<T: Into<String>, U: Into<String>>(self, name: T, value: U) -> Self
pub fn header<T: Into<String>, U: Into<String>>(self, name: T, value: U) -> Self
Sets a header for the response.
§Examples
let value = "custom header value";
let response = ResponseBuilder::new()
.header("X-Custom-Header", value)
.finish();
assert_eq!(
response
.headers()
.get("X-Custom-Header")
.unwrap(),
value
);
Sourcepub fn body<'a, B>(self, body: B) -> Self
pub fn body<'a, B>(self, body: B) -> Self
Sets the body of the response.
This will automatically set a Content-Type
header for the response depending on the body type.
§Examples
use azure_functions::http::{Body, Status};
let message = "The resouce was created.";
let response = ResponseBuilder::new()
.status(Status::Created)
.body(message)
.finish();
assert_eq!(response.status(), Status::Created);
assert_eq!(
response.body().as_str().unwrap(),
message
);
Sourcepub fn finish(self) -> HttpResponse
pub fn finish(self) -> HttpResponse
Consumes the builder and returns the HTTP response.
Trait Implementations§
Source§impl Debug for ResponseBuilder
impl Debug for ResponseBuilder
Source§impl Default for ResponseBuilder
impl Default for ResponseBuilder
Source§fn default() -> ResponseBuilder
fn default() -> ResponseBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ResponseBuilder
impl RefUnwindSafe for ResponseBuilder
impl Send for ResponseBuilder
impl Sync for ResponseBuilder
impl Unpin for ResponseBuilder
impl UnwindSafe for ResponseBuilder
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