Struct HttpRequest

Source
pub struct HttpRequest(/* private fields */);
Expand description

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()
}

Implementations§

Source§

impl HttpRequest

Source

pub fn method(&self) -> &str

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

Source

pub fn url(&self) -> &str

Gets the URL of the request.

Source

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

Gets the headers of the request.

The header keys are lower-cased.

Source

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

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.

Source

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

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()
}
Source

pub fn body(&self) -> Body<'_>

Gets the body of the request.

Trait Implementations§

Source§

impl Debug for HttpRequest

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more