Get Hello World

GET plain text, no parameters

  • JAX-RS Client API:

WebTarget target = ClientBuilder.newClient().target(RESOURCE_URL)
def response = target.request(TEXT_PLAIN_TYPE).get(String)
response == "Hello World!"
  • Jersey Groovy DSL:

def response = GET[RESOURCE_URL].text
response == "Hello World!"

(Press 'h' to highlight important sections of code.)

Get Hello Jersey

GET plain text, path parameter

  • JAX-RS Client API:

WebTarget target = ClientBuilder.newClient().target(RESOURCE_URL)
def response = target.path("Jersey").request(TEXT_PLAIN_TYPE).get(String)
response == "Hello Jersey!"
  • Jersey Groovy DSL:

def response = GET[RESOURCE_URL/"Jersey"].text
response == "Hello Jersey!"

(Press 'h' to highlight important sections of code.)

Get Hello Jersey

GET XML, path parameter

  • JAX-RS Client API:

WebTarget target = ClientBuilder.newClient().target(RESOURCE_URL)
def response = target.path("Jersey").request(APPLICATION_XML_TYPE).get(Message)
response instanceof Message
response.greeting == "Hello Jersey!"
  • Jersey Groovy DSL:

def response = (GET[RESOURCE_URL/"Jersey"] & APPLICATION_XML_TYPE) as Message
response instanceof Message
response.greeting == "Hello Jersey!"

(Press 'h' to highlight important sections of code.)

Post Hello Jersey

POST plain text, response text

  • JAX-RS Client API:

WebTarget target = ClientBuilder.newClient().target(RESOURCE_URL)
def Entity entity = Entity.entity("Jersey", TEXT_PLAIN_TYPE);
def response = target.request().post(entity, String)
response == "Hello Jersey!"
  • Jersey Groovy DSL:

def response = POST[RESOURCE_URL] << "Jersey" as String
response == "Hello Jersey!"

(Press 'h' to highlight important sections of code.)

Post Hello Jersey

POST object as JSON, response text

  • JAX-RS Client API:

WebTarget target = ClientBuilder.newClient().target(RESOURCE_URL)
def Entity entity = Entity.entity(new Message("Jersey", new Date()), APPLICATION_JSON_TYPE)
def response = target.request().post(entity, String)
response == "Hello Jersey!"
  • Jersey Groovy DSL:

def response = (POST[RESOURCE_URL] | APPLICATION_JSON_TYPE) \
                   << new Message("Jersey", new Date()) as String
response == "Hello Jersey!"

(Press 'h' to highlight important sections of code.)

<Thank You!>

Important contact information goes here.