summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-10-11 18:39:22 -0400
committerFrederic Guillot <fred@kanboard.net>2015-10-11 18:39:22 -0400
commitb0eebb71f626d62c84d9a2675db07a64d19aa9ee (patch)
tree280cab9ec5fd2af13f5ae9c1f7ccf16611d9368c
parentffe615d2018bdfb789667715bbde062dd696d320 (diff)
parent2328ae94c285251dcc31c59a9b70cab546d14405 (diff)
Merge pull-request #1354
-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
+```