On 11/09/2014 12:13 PM, Mathias LANG wrote:

On Fri, 07 Nov 2014 15:50:12 -0800, Toshiaki Takada wrote:

[...]
This looks OK, but suppose I have many fields associated with DB table
in backend, or I have sub-object in the JSON data, I would prefer to
process the POSTed data inside the function, not as function parameters.
So I wonder if I could get Json as a parameter.

I could be wrong, but I don't remember any special handling for Json in the REST module.
So, I would recommend that you go for an aggregate (e.g. a struct) instead. This work as long as you have full control (e.g., you control both client and server).

The other thing is, with above example, if I want to set 'null' to field
"a", like {"a":null}, it doesn't accept it, like:

There are two issues here. First I cannot set 'null' explicitly in any
fields. Second, for integer value, apparently it does not allow 'null'
as default in function declaration, so if I don't put the field in
POST/PUT data, it will fall back to default integer value, while I
expect to leave the value if unspecified.

Thanks,

--Toshiaki

For the first issue (null string), you can either pass "" (empty string), and it will work (in D, assert("" is null) pass).
Also, if you use an aggregate, you can put the @optional attribute on it.
Finally, for the integer, Nullable!int are handled correctly (see std.typecons).

Thanks for the comment. Actually, I found I can use @before to pass
Json as a parameter, like:

Json getJson(HTTPServerRequest req, HTTPServerResponse res)
{

return req.json;

}

@rootPathFromName
interface API
{

@before!getJson("json")
Json postRegister(Json json);

}

--T