RejectedSoftware Forums

Sign up

REST body as struct parameter

I've been using the REST framework for binding to a variety of services, but there's one use case that's come up repeatedly which does not seem to be supported: specifying the complete body of a request as a single parameter value in the interface.

It's often the case that one endpoint returns the exact same document structure that another expects as input. For example:

struct Details
{
  string name, description;
}

interface API
{
  Details get(string name);
  void add(Details details);
}

As far as I can see there's currently no nice way to make these methods use the same document structure. Either the Details argument for add will be wrapped in an additional details field in the Json body, or I have to duplicate the Details members as parameters for add instead of passing it as a typed struct.

Is there a clean way to do this?

Re: REST body as struct parameter

On Sun, 08 Jan 2017 22:26:30 GMT, Rene Zwanenburg wrote:

I've been using the REST framework for binding to a variety of services, but there's one use case that's come up repeatedly which does not seem to be supported: specifying the complete body of a request as a single parameter value in the interface.

...
As far as I can see there's currently no nice way to make these methods use the same document structure. Either the Details argument for add will be wrapped in an additional details field in the Json body, or I have to duplicate the Details members as parameters for add instead of passing it as a typed struct.

Is there a clean way to do this?

You might be interested in https://github.com/rejectedsoftware/vibe.d/pull/1676

Re: REST body as struct parameter

On Thu, 09 Feb 2017 19:26:44 GMT, Seb wrote:

On Sun, 08 Jan 2017 22:26:30 GMT, Rene Zwanenburg wrote:

I've been using the REST framework for binding to a variety of services, but there's one use case that's come up repeatedly which does not seem to be supported: specifying the complete body of a request as a single parameter value in the interface.

...
As far as I can see there's currently no nice way to make these methods use the same document structure. Either the Details argument for add will be wrapped in an additional details field in the Json body, or I have to duplicate the Details members as parameters for add instead of passing it as a typed struct.

Is there a clean way to do this?

You might be interested in https://github.com/rejectedsoftware/vibe.d/pull/1676

That looks perfect! I started working on adding a new @fullBody attribute, but it was a bit more involved than I had hoped.