<dependency>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-http-server-netty</artifactId>
</dependency>
<dependency>
<artifactId>micronaut-function-web</artifactId>
</dependency>
Once the dependencies have been added to the project, you can run the function via an class.
import io.micronaut.runtime.Micronaut
class Application {
static void main(String... args) {
Micronaut.run Application.class
}
}
You can now make requests against the function with a REST client.
$ curl -X GET http://localhost:8080/hello
The URI mapped to is defined by the either the value of the annotation for Java or, in the case of Groovy, the name of the function defined in the function script. The following tables summarizes the convention:
Functions that only return a value are mapped to HTTP GET
requests, whilst functions that accept an input require an HTTP POST
.