[][src]Struct azure_functions::bindings::HttpRequest

pub struct HttpRequest(_);

Represents a HTTP trigger binding.

The following binding attributes are supported:

NameDescription
nameThe name of the parameter being bound.
auth_levelDetermines what keys, if any, need to be present on the request in order to invoke the function. The authorization level can be one of the following values: anonymous, function, or admin.
methodsA list of HTTP methods to which the function responds, separated by | (e.g. get|post). If not specified, the function responds to all HTTP methods.
routeThe URL route to which the function responds. The default value is the name of the function.

Examples

A function that responds with a friendly greeting:

use azure_functions::{
    bindings::{HttpRequest, HttpResponse},
    func,
};

#[func]
pub fn greet(request: HttpRequest) -> HttpResponse {
    format!(
        "Hello, {}!",
        request.query_params().get("name").map_or("stranger", |x| x)
    ).into()
}

Methods

impl HttpRequest[src]

pub fn method(&self) -> &str[src]

Gets the HTTP method (e.g. "GET") for the request.

pub fn url(&self) -> &str[src]

Gets the URL of the request.

pub fn headers(&self) -> &HashMap<String, String>[src]

Gets the headers of the request.

The header keys are lower-cased.

pub fn route_params(&self) -> &HashMap<String, String>[src]

Gets the route parameters of the request.

Route parameters are specified through the route argument of a HttpRequest binding attribute.

See Route Containts for syntax.

Examples

use azure_functions::func;
use azure_functions::bindings::{HttpRequest, HttpResponse};

#[func]
#[binding(name = "request", route = "users/{id:int}")]
pub fn users(request: HttpRequest) -> HttpResponse {
    format!(
        "User ID requested: {}",
        request.route_params().get("id").unwrap()
    ).into()
}

Invoking the above function as https://<app-name>.azurewebsites.net/api/users/1234 would result in a response of User ID requested: 1234.

pub fn query_params(&self) -> &HashMap<String, String>[src]

Gets the query parameters of the request.

The query parameter keys are case-sensative.

Examples

use azure_functions::func;
use azure_functions::bindings::{HttpRequest, HttpResponse};

#[func]
pub fn users(request: HttpRequest) -> HttpResponse {
    format!(
        "The 'name' query parameter is: {}",
        request.query_params().get("name").map_or("undefined", |x| x)
    ).into()
}

pub fn body(&self) -> Body[src]

Gets the body of the request.

Trait Implementations

impl Debug for HttpRequest[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> IntoRequest<T> for T[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,