pub struct HttpRequest(/* private fields */);
Expand description
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()
}
Implementations§
Source§impl HttpRequest
impl HttpRequest
Sourcepub fn headers(&self) -> &HashMap<String, String>
pub fn headers(&self) -> &HashMap<String, String>
Gets the headers of the request.
The header keys are lower-cased.
Sourcepub fn route_params(&self) -> &HashMap<String, String>
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
.
Sourcepub fn query_params(&self) -> &HashMap<String, String>
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()
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HttpRequest
impl RefUnwindSafe for HttpRequest
impl Send for HttpRequest
impl Sync for HttpRequest
impl Unpin for HttpRequest
impl UnwindSafe for HttpRequest
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request