Looking for Cloud Services or Professional Support? Check restheart.com

Edit Page


Provider classes in RESTHeart work together with the @Inject and @OnInit annotations to form a Dependency Injection mechanism.

The Provider class

A Provider class must implements the interface Provider and must be annotated with @RegisterPlugin:

RegisterPlugin(name="hello-world-message", description="a dummy provider")
class MyProvider implements Provider<String> {
    public String get(PluginRecord<?> caller) {
        return "Hello World!";

Given the hello-world-message provider, we can inject its provided object into any Plugin with the @Inject annotation:

@RegisterPlugin(name = "greetings", description = "just another Hello World")
public class GreeterService implements JsonService {
    private String message;

    public void init() {
        // called after all @Inject fields are resolved

    public void handle(JsonRequest req, JsonResponse res) {
        switch(req.getMethod()) {
            case GET -> res.setContent(object().put("message", message));
            case OPTIONS -> handleOptions(req);
            default -> res.setStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED);

@RegisterPlugin annotation

The following table describes the arguments of the annotation:

param description mandatory default value


the name of the provider




description of the provider