{title:'REST Client Overview', created:'9.0.0'}

##### REST Client

Built upon the feature-rich Apache HttpClient library, the Juneau RestClient API adds support for fluent-style REST calls and the ability to perform marshalling of POJOs to and from HTTP parts.

##### Example:

| // Create a basic REST client with JSON support and download a bean. | MyBean bean = RestClient.create() | .simpleJson() | .build() | .get(URI) | .run() | .assertStatus().asCode().is(200) | .assertHeader("Content-Type").matchesSimple("application/json*") | .getContent().as(MyBean.class);

##### REST Testing Framework

The {@link oajr.mock.MockRestClient} class is used for performing serverless unit testing of {@link oajr.annotation.Rest @Rest}-annotated and {@link oaj.http.remote.Remote @Remote}-annotated classes.

##### Example:

| public class MockTest { | | // A simple bean with one field. | public static class MyBean { | public int foo = 1; | } | | // Our REST resource to test. | // Simply echos the response. | @Rest | public static class EchoRest implements BasicRestServlet { | | @RestPut | public MyBean echo(@Content MyBean bean) { | return bean; | } | } | | // Our JUnit test. | @Test | public void testEcho() throws Exception { | | MyBean myBean = new MyBean(); | | // Do a round-trip on the bean through the REST interface | myBean = MockRestClient | .create(EchoRest.class) | .simpleJson() | .build() | .put("/echo", myBean) | .run() | .assertStatus().is(200) | .assertContent().is("{foo:1}") | .getContent().as(MyBean.class); | | assertEquals(1, myBean.foo); | } | }

##### Additional Information

- {@doc juneau-rest-client} for more information.