Struct azure_functions::bindings::HttpResponseBuilder[][src]

pub struct HttpResponseBuilder(_);

Represents a builder for HTTP responses.

Methods

impl HttpResponseBuilder
[src]

Creates a new HttpResponseBuilder.

Sets the status for the response.

Examples

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.

Examples

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.

Examples

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
);

Trait Implementations

impl<'a> From<&'a mut HttpResponseBuilder> for HttpResponse
[src]

Performs the conversion.

impl Debug for HttpResponseBuilder
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations