summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorThomas Lutz <phoen1x@livingfire.de>2015-10-11 23:12:46 +0200
committerThomas Lutz <phoen1x@livingfire.de>2015-10-11 23:12:46 +0200
commit2328ae94c285251dcc31c59a9b70cab546d14405 (patch)
tree6e6c63be0c0aeec7cac92116f35cd0f4a6c10392 /doc
parentdc0749ecce232a5a68d83fbde965ee4ee8e36d00 (diff)
added Java example
Diffstat (limited to 'doc')
-rw-r--r--doc/api-json-rpc.markdown42
1 files changed, 41 insertions, 1 deletions
diff --git a/doc/api-json-rpc.markdown b/doc/api-json-rpc.markdown
index a7a8b546..359f8b05 100644
--- a/doc/api-json-rpc.markdown
+++ b/doc/api-json-rpc.markdown
@@ -248,6 +248,46 @@ end
puts response.body
```
+
+### Example with Java
+
+This is a basic example using Spring. For proper usage see [this link](http://spring.io/guides/gs/consuming-rest).
+
+```java
+import java.io.UnsupportedEncodingException;
+import java.util.Base64;
+
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.web.client.RestTemplate;
+
+public class ProjectService {
+
+ public void getAllProjects() throws UnsupportedEncodingException {
+
+ RestTemplate restTemplate = new RestTemplate();
+
+ String url = "http://localhost/kanboard/jsonrpc.php";
+ String requestJson = "{\"jsonrpc\": \"2.0\", \"method\": \"getAllProjects\", \"id\": 1}";
+ String user = "jsonrpc";
+ String apiToken = "19ffd9709d03ce50675c3a43d1c49c1ac207f4bc45f06c5b2701fbdf8929";
+
+ // encode api token
+ byte[] xApiAuthTokenBytes = String.join(":", user, apiToken).getBytes("utf-8");
+ String xApiAuthToken = Base64.getEncoder().encodeToString(xApiAuthTokenBytes);
+
+ // consume request
+ HttpHeaders headers = new HttpHeaders();
+ headers.add("X-API-Auth", xApiAuthToken);
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ HttpEntity<String> entity = new HttpEntity<String>(requestJson, headers);
+ String answer = restTemplate.postForObject(url, entity, String.class);
+ System.out.println(answer);
+ }
+}
+```
+
Procedures
----------
@@ -4510,4 +4550,4 @@ Response example:
}
]
}
-``` \ No newline at end of file
+```