@SuppressWarnings("unchecked") public void propertiesInvocation() { // tag::properties[] final PathProperty<Integer> CODE = create("code", int.class); final PathProperty<String> VALUE = create("value", String.class); final PropertySet<?> PROPERTIES = PropertySet.of(CODE, VALUE); RestClient client = RestClient.create(); PropertyBox box = client.request().target("https://rest.api.example").path("/apimethod").propertySet(PROPERTIES) .getForEntity(PropertyBox.class).orElse(null); // <1> Optional<PropertyBox> box2 = client.request().target("https://rest.api.example").path("/apimethod") .propertySet(CODE, VALUE).getForEntity(PropertyBox.class); // <2> List<PropertyBox> boxes = client.request().target("https://rest.api.example").path("/apimethod") .propertySet(PROPERTIES).getAsList(PropertyBox.class); // <3> // end::properties[] }
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[] }
List<TestData> collectionOfValues = client.request().getAsList(TestData.class);