Struct azure_functions::bindings::HttpRequest [−][src]
pub struct HttpRequest<'a>(_);
Represents a HTTP trigger binding.
Examples
A function that responds with a friendly greeting:
use azure_functions::func; use azure_functions::bindings::{HttpRequest, HttpResponse}; #[func] #[binding(name = "request", auth_level = "anonymous")] pub fn greet(request: &HttpRequest) -> HttpResponse { format!( "Hello, {}!", request.query_params().get("name").map_or("stranger", |x| x) ).into() }
Invoking the above function as https://<app-name>.azurewebsites.net/api/greet?name=John
would result in a response of Hello, John!
.
Methods
impl<'a> HttpRequest<'a>
[src]
impl<'a> HttpRequest<'a>
pub fn method(&self) -> &str
[src]
pub fn method(&self) -> &str
Gets the HTTP method (e.g. "GET") for the request.
pub fn url(&self) -> &str
[src]
pub fn url(&self) -> &str
Gets the URL of the request.
pub fn headers(&self) -> &HashMap<String, String>
[src]
pub fn headers(&self) -> &HashMap<String, String>
Gets the headers of the request.
pub fn route_params(&self) -> &HashMap<String, String>
[src]
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
.
pub fn query_params(&self) -> &HashMap<String, String>
[src]
pub fn query_params(&self) -> &HashMap<String, String>
Gets the URL query parameters of the request.
pub fn body(&self) -> Body
[src]
pub fn body(&self) -> Body
Gets the body of the request.
Trait Implementations
impl<'a> Debug for HttpRequest<'a>
[src]
impl<'a> Debug for HttpRequest<'a>
Auto Trait Implementations
impl<'a> Send for HttpRequest<'a>
impl<'a> Send for HttpRequest<'a>
impl<'a> Sync for HttpRequest<'a>
impl<'a> Sync for HttpRequest<'a>