Skip to content

[FEATURE] Provide a higher level implementation for REST handlers  #128

@dblock

Description

@dblock

Is your feature request related to a problem?

In https://github.com/opensearch-project/opensearch-sdk-java/blob/main/src/main/java/org/opensearch/sdk/sample/rest/RestHelloAction.java#L37 the developer has to implement a handleRequest that acts as a router that checks for methods, e.g.

if (Method.GET.equals(method) && "/hello".equals(uri)) {
            return new BytesRestResponse(OK, GREETING);
        }

This is unnecessarily verbose.

What solution would you like?

Provide a higher level implementation that implements ExtensionRestHandler . As a developer I would like to write something shorter:

public class RestHelloAction extends GenericExtensionRestHandler {

    @Override
    public List<Route> routes() {
        return singletonList(
            new RouteHandler(GET, "/hello", this.handleHello),
            new RouteHandler(GET, "/world", this.handleWorld)
        );
    }

    public RestResponse handleHello(...) {
    }

    public RestResponse handleWorld(...) {
    }
}

Alternatives?

There might be an HTTP handler library that provides routing out of the box that we could optionally plug in, e.g. https://github.com/undertow-io/undertow like so.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions