pub struct ResponseBuilder(_);
Represents a builder for HTTP responses.
Creates a new ResponseBuilder
.
Sets the status for the response.
use azure_functions::bindings::HttpResponse;
use azure_functions::http::Status;
let response: HttpResponse = HttpResponse::build()
.status(Status::InternalServerError)
.into();
assert_eq!(response.status(), Status::InternalServerError);
Sets a header for the response.
use azure_functions::bindings::HttpResponse;
let value = "custom header value";
let response: HttpResponse = HttpResponse::build()
.header("X-Custom-Header", value)
.into();
assert_eq!(
response
.headers()
.get("X-Custom-Header")
.unwrap(),
value
);
Sets the body of the response.
This will automatically set a Content-Type
header for the response depending on the body type.
use azure_functions::bindings::HttpResponse;
use azure_functions::http::{Body, Status};
let message = "The resouce was created.";
let response: HttpResponse = HttpResponse::build()
.status(Status::Created)
.body(message)
.into();
assert_eq!(response.status(), Status::Created);
assert_eq!(
match response.body() {
Body::String(s) => s,
_ => panic!("unexpected body.")
},
message
);
Formats the value using the given formatter. Read more