Am 04.09.2012 19:06, schrieb Casey Sybrandy:

Hello again,

Is it possible for vibe to handle being passed in complex documents as
parameters for a RESTful web service? I don't see any examples of this
in the vibe.httpd.rest module.

For example:

curl -i -XPOST -H "Content-Type: application/json"
http://localhost:8080/format -d '{"doc": { "foo": 1, "bar": "baz"}}'

I tried this with a method that looks like this:

string postFormat(string[string] doc)
{
..
}

This resulted in an error because 1 is not a string. My concern is if I
want to pass in more complex docs with several levels of nesting,
arrays, etc., is that possible using the rest module? Or, do I have to
handle it like a normal form upload and parse the JSON there?

These are the basic types that are possible:

  • int, string, ...
  • T[]
  • T[string]
  • struct/class
  • Json
  • Any type with toString()/fromString() is serialized as a string
  • For GET requests it's planned to send string parameters in the query
    string without quotes, but right now normal serialized JSON is sent for
    each parameter

So for the example you could either use a struct/class:

struct MyStruct { int foo; string bar; }
string postFormat(MyStruct doc) { ... }

or you could use Json/Json[string] to have a fully dynamic/flexible
document. The types can be arbitrarily nested.

I'll also add this to the documentation and to the rest example.