Changes between Version 3 and Version 4 of RestApi


Ignore:
Timestamp:
03.09.2011 01:02:37 (13 years ago)
Author:
jri
Comment:

Creating a simple topic

Legend:

Unmodified
Added
Removed
Modified
  • RestApi

    v3 v4  
    1414**About the curl examples:** 
    1515 
    16 The curl examples are ready for being pasted into a terminal. However, in order to get reasonable results you should adjust the IDs and example values 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. 
     16The 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. 
    1717 
    1818In 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. 
     
    2222=== Get topic by ID === 
    2323 
    24 **Request** 
    25  
    2624{{{ 
    2725GET /core/topic/<topic ID>[?fetch_composite=true/false] 
     
    3028The default for `fetch_composite` is `true`. 
    3129 
    32 Curl example 1: getting a topic ''with'' its `composite` value: 
     30==== Example 1: Getting a topic ''with'' its `composite` value ==== 
    3331 
    3432{{{ 
     
    3634}}} 
    3735 
    38 **Response** 
     36Response: 
    3937 
    4038{{{ 
     39HTTP/1.1 200 OK 
     40Content-Type: application/json 
     41 
    4142{ 
    4243  "id": 2676, 
     
    4647  "composite": { 
    4748    "dm4.notes.title": "What is DeepaMehta?", 
    48     "dm4.notes.text": "<p>DeepaMehta is a Post-Desktop-Metaphor user interface.</p>" 
     49    "dm4.notes.text": "<p>DeepaMehta is a think tool.</p>" 
    4950  } 
    5051} 
    5152}}} 
    5253 
    53 Curl example 2: getting a topic ''without'' its `composite` value: 
     54For details about the topic data format see DataFormat#topic. 
     55 
     56==== Example 2: Getting a topic ''without'' its `composite` value ==== 
    5457 
    5558{{{ 
     
    5760}}} 
    5861 
    59 **Response** 
     62Response: 
    6063 
    6164{{{ 
     65HTTP/1.1 200 OK 
     66Content-Type: application/json 
     67 
    6268{ 
    6369  "id": 2676, 
     
    7076}}} 
    7177 
    72 For details about the topic data format see DataFormat#topic. 
    73  
    7478If the topic doesn’t exist an error `500 Retrieving topic xy failed` is returned. 
    7579(The error response might become more HTTP/REST conform in the furure.) 
    7680 
    7781=== Create topic === 
    78  
    79 **Request** 
    8082 
    8183{{{ 
     
    8587}}} 
    8688 
    87 Curl example: 
     89==== Example 1: Creating a simple topic ==== 
    8890 
    8991{{{ 
    90 curl -X POST -H Content-Type:application/json -d ' 
    91 {type_uri: "dm4.notes.note", 
    92 composite: {dm4.notes.title: "My title", dm4.notes.text: "My text"} 
    93 }' localhost:8080/core/topic 
     92curl localhost:8080/core/topic -i \ 
     93-X POST \ 
     94-H Content-Type:application/json \ 
     95-d '{type_uri: "dm4.contacts.city", value: "Port-au-Prince"}' \ 
     96| jsonpretty 
    9497}}} 
    9598 
    9699For details about the topic data format see DataFormat#topic. 
    97100 
    98 **Response** 
     101Response: 
     102 
     103{{{ 
     104HTTP/1.1 200 OK 
     105Content-Type: application/json 
     106 
     107{ 
     108  "id": 3448, 
     109  "uri": "", 
     110  "type_uri": "dm4.contacts.city", 
     111  "value": "Port-au-Prince", 
     112  "composite": { 
     113  } 
     114} 
     115}}} 
     116 
     117==== Example 2: Creating a complex topic ==== 
     118 
     119{{{ 
     120curl localhost:8080/core/topic -i \ 
     121-X POST \ 
     122-H Content-Type:application/json \ 
     123-d '{type_uri: "dm4.notes.note", 
     124     composite: { 
     125       dm4.notes.title: "My title", 
     126       dm4.notes.text: "<p>My test text here<p>"}}' \ 
     127| jsonpretty 
     128}}} 
     129 
     130Response: 
    99131 
    100132{{{ 
     
    109141  "composite": { 
    110142    "dm4.notes.title": "My title", 
    111     "dm4.notes.text":"My text" 
     143    "dm4.notes.text":"<p>My test text here<p>" 
    112144  } 
    113145}