| ms.topic | include |
|---|---|
| author | ggailey777 |
| ms.service | azure-functions |
| ms.date | 11/14/2025 |
| ms.author | glenga |
The function.json file in the HttpExample folder declares an HTTP trigger function. You complete the function by adding a handler and compiling it into an executable.
-
Press Ctrl + N (Cmd + N on macOS) to create a new file. Save it as handler.go in the function app root (in the same folder as host.json).
-
In handler.go, add the following code and save the file. This is your Go custom handler.
package main import ( "fmt" "log" "net/http" "os" ) func helloHandler(w http.ResponseWriter, r *http.Request) { message := "This HTTP triggered function executed successfully. Pass a name in the query string for a personalized response.\n" name := r.URL.Query().Get("name") if name != "" { message = fmt.Sprintf("Hello, %s. This HTTP triggered function executed successfully.\n", name) } fmt.Fprint(w, message) } func main() { listenAddr := ":8080" if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok { listenAddr = ":" + val } http.HandleFunc("/api/HttpExample", helloHandler) log.Printf("About to listen on %s. Go to https://127.0.0.1%s/", listenAddr, listenAddr) log.Fatal(http.ListenAndServe(listenAddr, nil)) }
-
Press Ctrl + Shift + ` or select New Terminal from the Terminal menu to open a new integrated terminal in VS Code.
-
Compile your custom handler using the following command. An executable file named
handler(handler.exeon Windows) is output in the function app root folder.go build handler.go
-
Press Ctrl + Shift + ` or select New Terminal from the Terminal menu to open a new integrated terminal in VS Code.
-
In the function app root (the same folder as host.json), initialize a Rust project named
handler.cargo init --name handler
-
In Cargo.toml, add the following dependencies necessary to complete this quickstart. The example uses the warp web server framework.
[dependencies] warp = "0.3" tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
-
In src/main.rs, add the following code and save the file. This is your Rust custom handler.
use std::collections::HashMap; use std::env; use std::net::Ipv4Addr; use warp::{http::Response, Filter}; #[tokio::main] async fn main() { let example1 = warp::get() .and(warp::path("api")) .and(warp::path("HttpExample")) .and(warp::query::<HashMap<String, String>>()) .map(|p: HashMap<String, String>| match p.get("name") { Some(name) => Response::builder().body(format!("Hello, {}. This HTTP triggered function executed successfully.", name)), None => Response::builder().body(String::from("This HTTP triggered function executed successfully. Pass a name in the query string for a personalized response.")), }); let port_key = "FUNCTIONS_CUSTOMHANDLER_PORT"; let port: u16 = match env::var(port_key) { Ok(val) => val.parse().expect("Custom Handler port is not a number!"), Err(_) => 3000, }; warp::serve(example1).run((Ipv4Addr::LOCALHOST, port)).await }
-
Compile a binary for your custom handler. An executable file named
handler(handler.exeon Windows) is output in the function app root folder.cargo build --release cp target/release/handler .
The function host needs to be configured to run your custom handler binary when it starts.
-
Open host.json.
-
In the
customHandler.descriptionsection, set the value ofdefaultExecutablePathtohandler(on Windows, set it tohandler.exe). -
In the
customHandlersection, add a property namedenableForwardingHttpRequestand set its value totrue. For functions consisting of only an HTTP trigger, this setting simplifies programming by allow you to work with a typical HTTP request instead of the custom handler request payload. -
Confirm the
customHandlersection looks like this example. Save the file."customHandler": { "description": { "defaultExecutablePath": "handler", "workingDirectory": "", "arguments": [] }, "enableForwardingHttpRequest": true }
The function app is configured to start your custom handler executable.