Skip to content

Implement a 'forward' #5238

Answered by jrhee17
i1619khz asked this question in Q&A
Oct 14, 2023 · 3 comments · 4 replies
Discussion options

You must be logged in to vote

Perhaps if your method accepts an HttpRequest, you can call the other service manually.

I was literally imagining delegating the call to the service layer

static class SimpleClass {
    static HttpResponse methodA(ServiceRequestContext ctx, HttpRequest req) {
        if (req.path().equals("/")) {
            return methodB(ctx, req);
        }
        // do something
        return HttpResponse.of(200);
    }

    static HttpResponse methodB(ServiceRequestContext ctx, HttpRequest req) {
        // do something
        return HttpResponse.of(200);
    }
}

Server.builder()
      // delegate forwarding to the service layer
      .service("/v1", (ctx, req) -> SimpleClass.methodA(ctx, req))

I…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@i1619khz
Comment options

@jrhee17
Comment options

Answer selected by i1619khz
@i1619khz
Comment options

@jrhee17
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants