Request Format

From WarfishWiki

Jump to: navigation, search

Request format [back to top]

Warfish XML APIs accept REST style http requests of this form:

http://warfish.net/war/services/rest?_method=warfish.obj.methodname&_format=rest&arg1=val1

With these parameters:

  • _method - specifies the method name to call
  • _format - specifies the return data format which can be either "json" or "rest"
  • _jsonfunc - an optional parameter to specify the name of a js callback function (for _format=json, ignored for _format=rest) if one is desired. Otherwise the result is returned without a json callback function wrapper.
  • [additional method arguments] - in addition to the arguments described above an arbitrary number of addition arguments maybe required depending on the method being called. Illustrated above as "arg1=val1"

= Examples

Resulting data format examples [back to top]

Here is a sample of the output for each of the three differing output formats.

   * "_format=rest"
     <?xml version="1.0" encoding="utf-8" ?>
     <rsp stat="ok">
        <board width="1024" height="768" />
        <aboutme>Here is a little description about me.</aboutme>
        <table id="1" />
        <table id="2" />
        <table id="3" />
        <table id="4" />
     </rsp>
   * "_format=json"
     {
         "stat": "ok",
         "_content": {
             "board": { "width" : "1024",
                        "height" : "769" },
             "aboutme": { "_content" : "Here is a little description about me." },
             "table" : [ { "id" : "1" },
                         { "id" : "2" },
                         { "id" : "3" },
                         { "id" : "4" } ] }
         }
     }
     One thing to notice about the mapping between XML and JSON is that any content between open and close tags in XML is placed into a "_content" key value pair. You can see the two examples of "_content", the aboutme and rsp, above.
   * "_format=json&_jsonfunc=superfunc"
     superfunc({
         "stat": "ok",
         "_content": {
             "board": { "width" : "1024",
                        "height" : "769" },
             "aboutme": { "_content" : "Here is a little description about me." },
             "table" : [ { "id" : "1" },
                         { "id" : "2" },
                         { "id" : "3" },
                         { "id" : "4" } ] }
         }
     });

Notice then only difference between the last two samples is the wrapping javascript callback function "superfunc".

Personal tools