On Tue, 14 Jun 2016 08:58:15 GMT, Jacob Carlborg wrote:
I have a somewhat weird JSON API I'm trying to replicate in vibe.d using the rest interface generator. It uses query parameters for the top level keys of a JSON object and the values will be JSON objects (don't ask why). Example:
curl 'http://foobar.com/find_foo?ids=[1,2,3]'
(The JSON array needs to be URL encoded)
This works fine for GET requests but the API is similar for POST requests as well, but the data is passed in the body instead:
curl -d 'ids=[1,2,3]' http://foobar.com/update_foo
This way of passing the JSON data does not work for POST requests.
What's the best way to deal with this? I would really like to be able to use the rest interface generator because it's very convenient that (de)serialization is handle automatically. It's a bit inconsistent in vibe.d that it works with GET requests but not with POST request.
/Jacob Carlborg
Serialization formats for query and body parameters are currently unfortunately still hard-coded, but making that customizable is planned. It still shows that the REST generator was initially just intended as a simple means to provide a RESTful RPC mechanism and not to replicate existing REST APIs.
The exact API design for the customization still needs to be worked out. The basic idea would be to define a UDA à la @bodySerializer!TheSerializer
, but there are probably some details that require something more complex.