azure-functions 0.2.1

Azure Functions for Rust
docs.rs failed to build azure-functions-0.2.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: azure-functions-0.11.0

Azure Functions for Rust

The Azure Functions for Rust crate supports creating Azure Functions with Rust.

The following Azure Functions trigger bindings are supported:

The following Azure Functions input bindings are supported:

The following Azure Functions output bindings are supported:

Eventually more bindings will be implemented, including custom binding data.

Examples

Start by creating a new binary package:

$ cargo new --bin example

Edit Cargo.toml to include the following dependencies:

azure-functions = "0.2.1"
log = "0.4.2"

Azure Functions are implemented by applying a #[func] attribute to a Rust function.

For example, let's create src/greet.rs that implements a HTTP triggered function:

# extern crate azure_functions;
# #[macro_use] extern crate log;
use azure_functions::func;
use azure_functions::bindings::{HttpRequest, HttpResponse};

#[func]
#[binding(name = "request", auth_level = "anonymous")]
pub fn greet(request: &HttpRequest) -> HttpResponse {
// Log the request on the Azure Functions Host
info!("Request: {:?}", request);

// Return a formatted string as the response
format!(
"Hello from Rust, {}!",
request.query_params().get("name").map_or("stranger", |x| x)
).into()
}

Replace the contents of src/main.rs with the following to register the function with the Azure Functions Host:

#[macro_use]
extern crate log;
extern crate azure_functions;

mod greet;

// The main! macro generates an entrypoint for the binary
// Expects a list of Azure Functions to register with the Azure Functions host
azure_functions::main!{
greet::greet
}

Initialize the application with the init command, where $AzureWebJobsScriptRoot is the desired Azure Functions script root directory:

$ export AzureWebJobsScriptRoot=path-to-root
$ cargo run -q -- init --worker-path /tmp/example/rust_worker --script-root /tmp/example/root

Run the Azure Functions Host:

$ cd azure-functions-host/src/WebJobs.Script.WebHost
$ PATH=/tmp/example:$PATH AzureWebJobsScriptRoot=/tmp/example/root dotnet run

The above Azure Function can be invoked with http://localhost:5000/api/greet?name=John.

The expected response would be Hello from Rust, John!.