Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Enable RestResponse<headers, Mono<TBody>> #564

Open
anuchandy opened this issue Mar 4, 2019 · 3 comments
Open

[v3] Enable RestResponse<headers, Mono<TBody>> #564

anuchandy opened this issue Mar 4, 2019 · 3 comments
Assignees
Milestone

Comments

@anuchandy
Copy link
Member

anuchandy commented Mar 4, 2019

The DecodedResponse has the capability to emit lazy decoded body, bubble up this to RestResponseBase level so that we can support RestResponseBase<..., Mono<TBody>>

@anuchandy anuchandy added this to the Autorest V3.0 milestone Mar 4, 2019
@anuchandy anuchandy self-assigned this Mar 4, 2019
@anuchandy
Copy link
Member Author

@JonathanGiles as you pointed this is supported by .net (via T Task.Result)

@anuchandy
Copy link
Member Author

anuchandy commented Mar 4, 2019

RestResponse of this type should be Closable. When user subscribe outer mono:

Mono<RestResponseBase<..., Mono<TBody>>>

the request will be initiated then RestResponse will be created and emitted from the returned response.
The content will be drained only if user subscribe to Mono<TBody>, if user don't read the body then we need the ability to release the content hence closable.

@anuchandy
Copy link
Member Author

anuchandy commented Mar 5, 2019

The proxy interface looks like:

    @Host("http://httpbin.org")
    private interface HttpBinService {
        @PUT("put")
        Mono<RestResponseBase<HttpBinHeaders,Mono<HttpBinJSON>>> putBodyAndHeadersAsyncContentAsync(@BodyParam(ContentType.APPLICATION_OCTET_STREAM) String body);

        @PUT("put")
        RestResponseBase<HttpBinHeaders,Mono<HttpBinJSON>> putBodyAndHeadersContentAsync(@BodyParam(ContentType.APPLICATION_OCTET_STREAM) String body);
    }

The usage looks like:

Both response and body is async

final Mono<RestResponseBase<HttpBinHeaders, Mono<HttpBinJSON>>> asyncResponse = createService(HttpBinService.class)
        .putBodyAndHeadersAsyncContentAsync("body string");
//
asyncResponse.flatMap(response -> {
    //
    final Mono<HttpBinJSON> asyncBody = response.body();
    return asyncBody.flatMap(body -> {
        // "body string"
        System.out.println(body.data);
        return Mono.just(response.headers());
    });
})
.doOnNext(hdrs -> {
    final HttpBinHeaders headers = hdrs;
    System.out.println(headers.connection.toLowerCase());
})
.block();

response is sync and body is async

final RestResponseBase<HttpBinHeaders, Mono<HttpBinJSON>> response = createService(HttpBinService.class)
        .putBodyAndHeadersContentAsync("body string");
//
final Mono<HttpBinJSON> asyncBody = response.body();
asyncBody.doOnNext(body -> {
            // "body string"
        System.out.println(body.data);
})
.block();

final HttpBinHeaders headers = response.headers();
System.out.println(headers.connection.toLowerCase());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant