-
Notifications
You must be signed in to change notification settings - Fork 0
Rest Client
#The SBT Rest Client The RestClient is a set of lightweight HTTP libraries for performing most types of HTTP requests. Features
- GET, POST ,PUT and DELETE operations.
- Handles JSON, XML, and Atom responses as well as String/Raw responses.
- Supports URL parameters, file uploads and custom body entities.
- Supports Basic Authentication.
- Supports custom headers.
You need the com.ibm.sbt.core.jar dependency. You can add this to your project by creating a maven project and listing the sbt.core.jar as a dependency or manually add the jar and its dependencies from the social business toolkit build.
RestClient restClient = new RestClient("serverUrl","username","password"); Response<AtomFeed> responseFeed = restClient.doGet("/api/resource").asAtomFeed();
Or Statically
RestClient.get("http://server/api/resource").basicAuth("username","password").asJson();
You can also create a client using an existing endpoint.
BasicEndpoint endpoint = new BasicEndpoint(); endpoint.setUrl("http://serverUrl.com"); endpoint.setUser("username"); endpoint.setPassword("password"); RestClient client = new RestClient(endpoint);
Or you can create the RestClient using an endpoint defined in a ManagedBeans.xml file.
RestClient restClient = new RestClient("IBMConnections");