public RESTClient(int port) {
urlStem = "http://localhost:" + port + "/services/membership/members/";
}
public void run() throws Exception {
Person p = getMember(1);
System.out.println("Updating person name using PUT and .../members/1/name URL:");
WebClient wc = WebClient.create(urlStem);
wc.path("1");
wc.path("name").type("text/plain");
Response resp = wc.put("George".equals(p.getName()) ? "Sam" : "George");
// for PUTS, resp.getStatus() returns 204 if success, 404 if ID couldn't
// be found
p = getMember(1);
System.out.println("Updating multiple fields of the person using PUT and .../members/1 URL:");
p.setName("Bob");
p.setAge(p.getAge() == 40 ? 30 : 40);
resp = wc.reset().path("1").put(p);
p = getMember(1);
System.out.println("Creating a new member using POST and .../members/1 URL:");
Person newMember = new Person();
newMember.setName("Harry");
newMember.setAge(30);
resp = wc.reset().post(newMember);
if (resp.getStatus() != Response.Status.CREATED.getStatusCode()) {
throw new RuntimeException("Could not add new member.");
}