@SuppressWarnings("rawtypes") public void request() { // tag::request[] RequestEntity<String> request1 = RequestEntity.text("test"); // <1> RequestEntity<TestData> request2 = RequestEntity.json(new TestData()); // <2> RequestEntity request3 = RequestEntity .form(RequestEntity.formBuilder().set("value1", "one").set("value2", "a", "b").build()); // <3> // end::request[] }
@SuppressWarnings("rawtypes") public void request() { // tag::request[] RequestEntity<String> request1 = RequestEntity.text("test"); // <1> RequestEntity<TestData> request2 = RequestEntity.json(new TestData()); // <2> RequestEntity request3 = RequestEntity .form(RequestEntity.formBuilder().set("value1", "one").set("value2", "a", "b").build()); // <3> // end::request[] }
response = client.request().get(ResponseType.of(TestData.class)); // <2> response = client.request().put(RequestEntity.json(new TestData()), TestData.class); // <3> ResponseEntity<Void> response2 = client.request().post(RequestEntity.json(new TestData())); // <1> Optional<URI> locationHeaderURI = client.request().postForLocation(RequestEntity.json(new TestData()));
response = client.request().get(ResponseType.of(TestData.class)); // <2> response = client.request().put(RequestEntity.json(new TestData()), TestData.class); // <3> Mono<ReactiveResponseEntity<Void>> response2 = client.request().post(RequestEntity.json(new TestData())); // <1> response2.doOnSuccess(r -> { Mono<URI> locationHeaderURI = client.request().postForLocation(RequestEntity.json(new TestData()));
public void restClient() throws URISyntaxException { // tag::restclient[] final PathProperty<Integer> ID = PathProperty.create("id", Integer.class); final PathProperty<String> NAME = PathProperty.create("name", String.class); final PropertySet<?> PROPERTY_SET = PropertySet.of(ID, NAME); RestClient client = JaxrsRestClient.create() // <1> .defaultTarget(new URI("https://host/api")); // <2> client = RestClient.create(JaxrsRestClient.class.getName()); // <3> client = RestClient.create(); // <4> client = RestClient.forTarget("https://host/api"); // <5> Optional<TestData> testData = client.request().path("data/{id}").resolve("id", 1) // <6> .accept(MediaType.APPLICATION_JSON).getForEntity(TestData.class); Optional<PropertyBox> box = client.request().path("getbox") // <7> .propertySet(PROPERTY_SET).getForEntity(PropertyBox.class); HttpResponse<PropertyBox> response = client.request().path("getbox") // <8> .propertySet(PROPERTY_SET).get(PropertyBox.class); List<PropertyBox> boxes = client.request().path("getboxes") // <9> .propertySet(PROPERTY_SET).getAsList(PropertyBox.class); PropertyBox postBox = PropertyBox.builder(PROPERTY_SET).set(ID, 1).set(NAME, "Test").build(); HttpResponse<Void> postResponse = client.request().path("postbox") // <10> .post(RequestEntity.json(postBox)); // end::restclient[] }
public void restClient() throws URISyntaxException { // tag::restclient[] final PathProperty<Integer> ID = PathProperty.create("id", Integer.class); final PathProperty<String> NAME = PathProperty.create("name", String.class); final PropertySet<?> PROPERTY_SET = PropertySet.of(ID, NAME); AsyncRestClient client = JaxrsAsyncRestClient.create() // <1> .defaultTarget(new URI("https://host/api")); // <2> client = AsyncRestClient.create(JaxrsAsyncRestClient.class.getName()); // <3> client = AsyncRestClient.create(); // <4> client = AsyncRestClient.forTarget("https://host/api"); // <5> CompletionStage<Optional<TestData>> testData = client.request().path("data/{id}").resolve("id", 1) // <6> .accept(MediaType.APPLICATION_JSON).getForEntity(TestData.class); CompletionStage<Optional<PropertyBox>> box = client.request().path("getbox") // <7> .propertySet(PROPERTY_SET).getForEntity(PropertyBox.class); CompletionStage<ResponseEntity<PropertyBox>> response = client.request().path("getbox") // <8> .propertySet(PROPERTY_SET).get(PropertyBox.class); CompletionStage<List<PropertyBox>> boxes = client.request().path("getboxes") // <9> .propertySet(PROPERTY_SET).getAsList(PropertyBox.class); PropertyBox postBox = PropertyBox.builder(PROPERTY_SET).set(ID, 1).set(NAME, "Test").build(); CompletionStage<ResponseEntity<Void>> postResponse = client.request().path("postbox") // <10> .post(RequestEntity.json(postBox)); // end::restclient[] }
public void restClient() throws URISyntaxException { // tag::restclient[] final PathProperty<Integer> ID = PathProperty.create("id", Integer.class); final PathProperty<String> NAME = PathProperty.create("name", String.class); final PropertySet<?> PROPERTY_SET = PropertySet.of(ID, NAME); ReactiveRestClient client = JaxrsReactiveRestClient.create() // <1> .defaultTarget(new URI("https://host/api")); // <2> client = ReactiveRestClient.create(JaxrsReactiveRestClient.class.getName()); // <3> client = ReactiveRestClient.create(); // <4> client = ReactiveRestClient.forTarget("https://host/api"); // <5> Mono<TestData> testData = client.request().path("data/{id}").resolve("id", 1) // <6> .accept(MediaType.APPLICATION_JSON).getForEntity(TestData.class); Mono<PropertyBox> box = client.request().path("getbox") // <7> .propertySet(PROPERTY_SET).getForEntity(PropertyBox.class); Mono<ReactiveResponseEntity<PropertyBox>> response = client.request().path("getbox") // <8> .propertySet(PROPERTY_SET).get(PropertyBox.class); Flux<PropertyBox> boxes = client.request().path("getboxes") // <9> .propertySet(PROPERTY_SET).getAsList(PropertyBox.class); PropertyBox postBox = PropertyBox.builder(PROPERTY_SET).set(ID, 1).set(NAME, "Test").build(); Mono<ReactiveResponseEntity<Void>> postResponse = client.request().path("postbox") // <10> .post(RequestEntity.json(postBox)); // end::restclient[] }