Install IntelliJ Community Edition: https://www.jetbrains.com/idea/download/?section=windows
Run IntelliJ Community Edition
Install "Azure Toolkit for IngelligJ" plugin
Create a new project
Select "Azure Functions", Function trigger "HttpTrigger", project SDK "Oracle openJDK version 20.0.1":
Select project manager tool "Maven", group name "com.example", artifact "azure-function-examples", version "1.0.0-SNAPSHOT", package name "org.example.functions":
Also set the project name "azure-function-examples" and project location "C:\azure-function-examples":
To avoid any problem with the Antivirus configure Microsoft Defender automatically:
This is the project structure:
This is the Azure Java Function source code:
package org.example.functions;
import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;
/**
* Azure Functions with HTTP Trigger.
*/
public class HttpTriggerJava {
/**
* This function listens at endpoint "/api/HttpTriggerJava". Two ways to invoke it using "curl" command in bash:
* 1. curl -d "HTTP Body" {your host}/api/HttpTriggerJava
* 2. curl {your host}/api/HttpTriggerJava?name=HTTP%20Query
*/
@FunctionName("HttpTriggerJava")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) {
context.getLogger().info("Java HTTP trigger processed a request.");
// Parse query parameter
String query = request.getQueryParameters().get("name");
String name = request.getBody().orElse(query);
if (name == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
}
}
}Run the application:
See the application output:
We input the Azure Function endpoint URL in the internet web browser:
http://localhost:54658/api/HttpTriggerJava
Also we can set the "name" parameter as a querystring in the above URL:
http://localhost:54658/api/HttpTriggerJava?name="my name is John"
Before deploying the Azure Java Function in the Azure Portal we can the deployment region "westeurope" in the pom.xml file:
We deploy the application clicking on the "Deploy to Azure..." link:
If you previously created a Function in Azure Portal then select it, otherwise we create a new Function in Azure portal to host our application
When the deployment is finished you can Login in Azure Portal and inside the Azure Functions list we select our new Function
We click on the button "Get Function Url" to copy the Azure Function URL:
We can also set the "name" parameter as a querystring in the Function URL endpoint:























