In previous posts, we introduced the REST API with samples in DotNet, Ruby, and PHP. In today's post, we'll introduce a request library written in Java that we're opening up to the community. The code is publicly available on Githib at : https://github.com/fredsakr/java-rest-client
The library supports the following operations :
- GET
- POST
- PUT
- DELETE
Usage
import com.rest.api.*; Client client = new Client(site + "\\" + user, password, baseUrl);
GET
Retrieve a single entity :
Response response = client.get("/data/contact/"+String.valueOf(id));
Retrieve (search) for a list of entities
Response response = client.get("/data/contacts?search="+search+"&page="+page+"&count="+count);
POST
Response response = client.post("/data/contact", body);
PUT
int contactId = 1; Response response = client.put("/data/contact/" + String.valueOf(contactId), body);
DELETE
int contactId = 1; client.delete("/data/contact/" + String.valueOf(contactId));
Please note that the code samples available here are my own work. I'll be glad to help support and fix issues in the code, but please understand that Eloqua will not be able to support this.
Thanks,
Fred