Changeset 10662


Ignore:
Timestamp:
02/07/11 04:56:31 (2 years ago)
Author:
SvenDowideit
Message:

Item2321: update docco for RestPlugin - add example how to use foswiki.RestPlugin

Location:
trunk/RestPlugin
Files:
5 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/RestPlugin/data/Sandbox/TestRestPlugin.txt

    r10585 r10662  
    4848        $('#query_output').text('SUBMITTING'); 
    4949         
    50         //this is equivalent to: 
     50        //this is equivalent to (but with valid strikeone validation): 
    5151        //curl -X PATCH -H "Content-Type:text/json" -d '{"_text": "curl is it"}' http://x61/f/bin/query/Sandbox/TestTopic0/topic.json 
    5252 
  • trunk/RestPlugin/data/System/RestPlugin.txt

    r10583 r10662  
    3333   5 more serialisations - including www-form.. 
    3434   6 make =OPTIONS= response contextural 
    35 ---+++ Resources 
     35---+++ Resource types (/web,/topic,/attachment) 
    3636---++++ Web 
    3737| *Verb*   | *Implemented* | *URI*                                               | *Use* | 
    38 | =GET=    |     yes       | =http://x61/bin/query/[{Webname}/]webs[.json]=      |  get web resource information, currently a list of subwebs to the resource (if no Webname is specified, list all webs)    | 
    39 | =POST=   |     yes       | =http://x61/bin/query/[{Webname}/]webs[.json]=      |  create a new web in the uri's container web - parameters in payload as for the manage=createWeb     | 
     38| =GET=    |     yes       | =http://x61/bin/query[/{Webname}]/webs[.json]=      |  get web resource information, currently a list of subwebs to the resource (if no Webname is specified, list all webs)    | 
     39| =POST=   |     yes       | =http://x61/bin/query[/{Webname}]/webs[.json]=      |  create a new web in the uri's container web - parameters in payload as for the manage=createWeb     | 
    4040| =PUT=    |     no        | =http://x61/bin/query/{Webname}/webs[.json]=        |  update a web resource (=nop= until define some web specific info, like permissions, settings etc), or maybe for renaming a web?)     | 
    4141| =PATCH=  |     no        | =http://x61/bin/query/{Webname}/webs[.json]=        |  same as PUT?     | 
     
    4343---++++ Topic 
    4444| *Verb*   | *Implemented* | *URI*                                               | *Use* | 
    45 | =GET=    |     yes       | =http://x61/bin/query/{Webname}/[{TopicName/}]topic[.json]=      |  get topic's meta (if no TopicName is specified, list of all topics in a web. (array of names only?))    | 
     45| =GET=    |     yes       | =http://x61/bin/query/{Webname}[/{TopicName}]/topic[.json]=      |  get topic's meta (if no TopicName is specified, array of all topic names in a web.)    | 
    4646| =POST=   |     yes       | =http://x61/bin/query/{Webname}/topic[.json]=                    |  (TODO: might rejig to use UI::Manage::_create) create a new topic in the web container using the payload as topic data, and respecting AUTOINC name requests | 
    4747| =PUT=    |     no        | =http://x61/bin/query/{Webname}/{TopicName}/topic[.json]=        |  update/create a topic resource completely with the payload - anything missing from the sent structure will be removed in the new revision, will not respect AUTOINC, and will use the topic name in the URI, not the payload. | 
     
    5050---++++ Attachments 
    5151| *Verb*   | *Implemented* | *URI*                                               | *Use* | 
    52 | =GET=    |     yes       | =http://x61/bin/query/{Webname}/{TopicName}/[{attachmentname}/]attachments[.json]=      |  get attachment resource information, currently a list of subwebs to the resource (if no Webname is specified, list all webs)    | 
     52| =GET=    |     yes       | =http://x61/bin/query/{Webname}/{TopicName}[/{attachmentname}]/attachments[.json]=      |  get attachment resource information, currently a list of subwebs to the resource    | 
    5353| =POST=   |     no        | =http://x61/bin/query/{Webname}/{TopicName}/attachments[.json]=                         |  create a new attachment - can I just decode the payload and push to UI::Upload?     | 
    5454| =PUT=    |     no        | =http://x61/bin/query/{Webname}/{TopicName}/{attachmentname}/attachments[.json]=        |  update a attachment resource (=nop= until define some web specific info, like permissions, settings etc), or maybe for renaming a web?)     | 
     
    6767will give simple docco about what requests are supported 
    6868---++++ GET 
     69retreives a resource, or an array of resource names 
    6970---++++ PUT 
     71not implemented yet 
    7072---++++ POST 
    7173Creates a new element in a container. So if you want to create a new topic, the URI is that of the web you want to place it, and the payload will contain a value that has a =_topic= 
     
    7375modifies an existing item, changing only the elements sent in the payload - thus allowing you to modify just the topic text, the value of one 'named' FIELD, or one Attachement's data. 
    7476---++++ DELETE 
     77delete the specified resource 
     78---+++ Examples: 
     79---++++ Using the built in =foswiki.RestPlugin= javascript helper 
     80<verbatim class="tml"> 
     81%ADDTOZONE{"script" text="<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/RestPlugin/json2.js'></script>" id="json2.js"}% 
     82%ADDTOZONE{"script"  
     83    text="<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/RestPlugin/foswikiRestPlugin.js'></script>" id="foswikiRestPlugin.js"  
     84    requires="json2.js, JavascriptFiles/foswikiPref, JavascriptFiles/strikeone" 
     85}% 
     86var query = 'Sandbox/TestTopic0'; 
     87var element = 'topic'; 
     88var encoding = 'json'; 
     89        foswiki.RestPlugin.get(query, {element:element, encoding:encoding, success_callback:showResponse}); 
     90        //you need at least one 'get' query to ensure you have a valid strikeone nonce loaded before you can use it to do a change operation 
     91        foswiki.RestPlugin.patch(query, { 
     92                                _text: newtext,  
     93                                FORM: [{name: 'BugItemTemplate'}],  
     94                                FIELD : [{name:'Summary', value:'oh. i have to fill it in?'}] 
     95                      },  
     96                      { 
     97                            element:element,  
     98                            encoding:encoding,  
     99                            success_callback:showResponse 
     100                      }); 
     101// post-success callback  
     102function showResponse(responseText, statusText, xhr)  {  
     103    var text = ''; 
     104    if ((typeof responseText) == 'string') { 
     105        text = responseText; 
     106    } else { 
     107        text = responseText._text; 
     108    } 
    75109 
    76 ---+++ Examples: 
     110    var nonce = ''; 
     111    //show the nonce changes for debugging 
     112    if ((typeof(foswiki.RestPlugin.nonce) == 'undefined') || (foswiki.RestPlugin.nonce == '')) { 
     113        nonce = 'nonce not found'; 
     114    } else { 
     115        nonce = foswiki.RestPlugin.nonce; 
     116    } 
     117    alert('nonce = '+nonce + ' text = ' + text); 
     118} 
     119</verbatim> 
     120---++++ using =curl= to get topic data. 
     121<verbatim> 
     122curl -X GET -H "Content-Type:text/json" http://x61/f/bin/query/Sandbox/TestTopic0/topic.json 
     123</verbatim> 
     124<div style="display:none;"> 
     125BROKEN when strikeone is on 
    77126---++++ using =curl= to update topic data. 
    78127__now that the strikeone support is added, these example only work with Validation=none__ fix to come 
     
    85134curl -X PATCH -H "Content-Type:text/json" -d @- 'http://x61/f/bin/query/Main/SvenDowideit/topic.json' 
    86135</verbatim> 
    87  
     136</div> 
    88137---++ Installation Instructions 
    89138 
     
    91140 
    92141---++ Plugin Info 
     142 
     143Many thanks to the following sponsors for supporting this work: 
     144   * [[http://www.taxonomy.org.au][TRIN]], The Taxonomy Research & Information Network with the [[http://www.anbg.gov.au/cpbr/][Centre for Australian National Biodiversity Research]] 
     145 
    93146 
    94147 
Note: See TracChangeset for help on using the changeset viewer.