An extended version of this tutorial, adding a Cloudant NoSQL Database and D3js data visualization, is available here.
- Bluemix account
- Github account
- Create the StarterApp
- Add the Toolchain or Continuous Integration (CI)
- REST API Primer
- Authentication in REST API
- Getting the Bluemix Configuration
- Add the AlchemyData News API Client
- Add a Web Form
- Implement the AlchemyData News API Request
- Create Authorization Header for Basic Auth
1. Create the StarterApp
Note: this API needs to be updated to v2. Identify is now a resource on the Language Translation API.
Making an HTTP REST API POST request in Java is in principle as simple this:
Request request = Request.Post(serviceURI)
Executor executor = Executor.newInstance();
String response = executor.execute(request).returnContent().asString();
This code, uses the Apache Fluent API, which exposes only the essentials of the Apache HTTPClient.
The Authorization header is required for authentication by the Watson API, and is a base64 encoded string.
String auth = username + ":" + password;
String basicAuthorization = "Basic "+ Base64.encodeBase64String(auth.getBytes());
The POST request is “x-www-form-urlencoded” and in Java consists of a List<NameValuePair>:
List<NameValuePair> params = new ArrayList<NameValuePair>();
Add the following Java archives to your build path in Eclipse on Mac OS X: