September 2019
Intermediate to advanced
816 pages
18h 47m
English
The following solution updates the email address of the user we fetched in the preceding subsection:
user.getData().setEmail("newemail@gmail.com");HttpRequest requestPut = HttpRequest.newBuilder() .header("Content-Type", "application/json") .uri(URI.create("https://reqres.in/api/users")) .PUT(HttpRequest.BodyPublishers.ofString(jsonb.toJson(user))) .build();HttpResponse<User> responsePut = client.send( requestPut, JsonBodyHandler.jsonBodyHandler(jsonb, User.class));User updatedUser = responsePut.body();