diff options
author | Alex Shpak <alex-shpak@users.noreply.github.com> | 2018-09-30 01:31:24 +0200 |
---|---|---|
committer | Alex Shpak <alex-shpak@users.noreply.github.com> | 2018-09-30 01:31:24 +0200 |
commit | 5b7db23aaacbb08a8242b1a77bd39bc19139526c (patch) | |
tree | b36f8ab16b89f1ae475db883f3f91b2a0a6837b8 /exampleSite/content/docs/rx-jersey-client.md | |
parent | 7a6ab6d72496a07e42aa03242891b6d815b26b0d (diff) |
Add exampleSite
Diffstat (limited to 'exampleSite/content/docs/rx-jersey-client.md')
-rw-r--r-- | exampleSite/content/docs/rx-jersey-client.md | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/exampleSite/content/docs/rx-jersey-client.md b/exampleSite/content/docs/rx-jersey-client.md new file mode 100644 index 0000000..b0e2793 --- /dev/null +++ b/exampleSite/content/docs/rx-jersey-client.md @@ -0,0 +1,60 @@ +## RxJersey Proxy Client + +Proxy client provides convenient way to call resources without constructing request. Also it allows to reuse resource interfaces between microservices. + +In order to enable RxJava in proxy client register Jersey feature +```java +RxJerseyClientFeature rxJerseyClientFeature = new RxJerseyClientFeature() + .register(client); //should be non-blocking client implementation +resourceConfig.register(rxJerseyClientFeature); +``` +Default client with Grizzly connector will be used if not provided + + +## Remote resource injection +You can inject proxy client with `@Remote` annotation, in addition you can inject `WebTarget` or `RxWebTarget` +```java +@Path("/example/") +public class GithubResource { + + @Remote("https://api.github.com/") + private GithubApi githubApi; + + @Remote("https://api.github.com/") + private WebTarget webTarget; + + @GET + @Path("github") + public Single<GithubRepository> getRepository() { + return githubApi.getRepository("alex-shpak", "rx-jersey").toSingle(); + } +} +``` + +## Manual proxy client creation +You can use `WebResourceFactory` from `net.winterly.rxjersey.client` package in order to create proxy client + +#### RxJava +```java +WebResourceFactory.newResource( + ResourceInterface.class, + rxWebTarget, + new ObservableClientMethodInvoker() +); +``` +#### RxJava 2 +```java +WebResourceFactory.newResource( + ResourceInterface.class, + webTarget, + new FlowableClientMethodInvoker() +); +``` + +## Url resolving +Below is example of URL merging based on `@Remote` annotation value + +| Annotation Value | Jersey Context Path | Result URL | +| ----------------------------- | --------------------------- | ---------------------------- | +| @Remote("http://example.com") | http://baseurl.com/resource | http://example.com/ | +| @Remote("/resource/") | http://baseurl.com/some | http://baseurl.com/resource/ |
\ No newline at end of file |