[−][src]Struct azure_functions::bindings::HttpRequest
Represents a HTTP trigger binding.
The following binding attributes are supported:
Name | Description |
---|---|
name | The name of the parameter being bound. |
auth_level | Determines 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 . |
methods | A 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. |
route | The 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
Auto Trait Implementations
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnwindSafe for HttpRequest
impl RefUnwindSafe for HttpRequest
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> IntoRequest<T> for T
[src]
fn into_request(self) -> Request<T>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,