RejectedSoftware Forums

Sign up

REST api constantly crashes

Hi,

I am trying to use the autogenerated api, but it crashes, if I try to use paths with parameters. Here is my code:

interface IRESTApi
{
  @method(HTTPMethod.GET)
  @path("/status/:item/")
  @property Json status(string item);
}

...

auto router = new URLRouter();
router.registerRestInterface(cast(IRESTApi)this);

this references a class implementing a Json status(string item) method

Now, when I open in browser the page http://127.0.0.1:8080/status/environment/, I get this output with LogLevel.trace:

route match: /status/environment/ -> GET /status/:item/ ["environment"]
query item of DictionaryList!(string, true, 16u)([Field(0, "", ""), Field(0, "",
 ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Fi
eld(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "
", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""), Field(0, "", ""),
Field(0, "", "")], 0, [])

Problem is that this is the last thing I see. Then it simply crashes somewhere in kernel after calling std@stdio@File@LockingTextWriter@__dtor.

If I use method without parameter, it works like a charm. But when I try to use parameters, it just blows up :-/

Any ideas, what is wrong?

Thanks,
Drasha

Re: REST api constantly crashes

On Tue, 06 Jan 2015 14:37:45 GMT, Drasha wrote:

interface IRESTApi
{
  @method(HTTPMethod.GET)
  @path("/status/:item/")
  @property Json status(string item);
}

...

auto router = new URLRouter();
router.registerRestInterface(cast(IRESTApi)this);

Ultimately, what's wrong is that your parameter needs to be called '_item', not 'item'.

There is however a bug here (reported recently: https://github.com/rejectedsoftware/vibe.d/issues/949 ), as the interface should report the error.

Side note: Unless your interface implements multiple interfaces, you don't need to cast.

Re: REST api constantly crashes

On Tue, 06 Jan 2015 20:44:36 GMT, Mathias LANG wrote:

Ultimately, what's wrong is that your parameter needs to be called '_item', not 'item'.

Ha! That was it. Thanks a lot!

There is however a bug here (reported recently: https://github.com/rejectedsoftware/vibe.d/issues/949 ), as the interface should report the error.

Side note: Unless your interface implements multiple interfaces, you don't need to cast.

It does and vibe was complaining, so that's why I added it.

Thanks again,
Drasha