wiki:RestApi

Version 4 (modified by jri, 9 years ago) (diff)

Creating a simple topic

DeepaMehta REST API

The DeepaMehta application service is accessible via a REST API.

About the REST API:

All requests return application/json data.

For requests that take data in the request body: The data is expected to be of type application/json as well. So, don’t forget to set the request’s Content-Type header accordingly. Otherwise an error is returned (as application/x-www-form-urlencoded is used as the default).

About the curl examples:

The curl examples are ready for being pasted into a terminal. However, the IDs must be adjusted to your actual DB content. Hint: to determine a topic's or association's ID click it in the webclient and read the console log.

In order to make the responses more readable the curl examples make use of the jsonpretty tool. Jsonpretty is installable as a Ruby gem. See http://github.com/nicksieger/jsonpretty.

Topics

Get topic by ID

GET /core/topic/<topic ID>[?fetch_composite=true/false]

The default for fetch_composite is true.

Example 1: Getting a topic with its composite value

curl localhost:8080/core/topic/2676 | jsonpretty

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 2676,
  "uri": "",
  "type_uri": "dm4.notes.note",
  "value": "What is DeepaMehta?",
  "composite": {
    "dm4.notes.title": "What is DeepaMehta?",
    "dm4.notes.text": "<p>DeepaMehta is a think tool.</p>"
  }
}

For details about the topic data format see DataFormat#topic.

Example 2: Getting a topic without its composite value

curl localhost:8080/core/topic/55?fetch_composite=false | jsonpretty

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 2676,
  "uri": "",
  "type_uri": "dm4.notes.note",
  "value": "What is DeepaMehta?",
  "composite": {
  }
}

If the topic doesn’t exist an error 500 Retrieving topic xy failed is returned. (The error response might become more HTTP/REST conform in the furure.)

Create topic

POST /core/topic

<the topic>

Example 1: Creating a simple topic

curl localhost:8080/core/topic -i \
-X POST \
-H Content-Type:application/json \
-d '{type_uri: "dm4.contacts.city", value: "Port-au-Prince"}' \
| jsonpretty

For details about the topic data format see DataFormat#topic.

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 3448,
  "uri": "",
  "type_uri": "dm4.contacts.city",
  "value": "Port-au-Prince",
  "composite": {
  }
}

Example 2: Creating a complex topic

curl localhost:8080/core/topic -i \
-X POST \
-H Content-Type:application/json \
-d '{type_uri: "dm4.notes.note",
     composite: {
       dm4.notes.title: "My title",
       dm4.notes.text: "<p>My test text here<p>"}}' \
| jsonpretty

Response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 3298,
  "uri": "",
  "type_uri": "dm4.notes.note",
  "value": "My title",
  "composite": {
    "dm4.notes.title": "My title",
    "dm4.notes.text":"<p>My test text here<p>"
  }
}