I've a problem where the RestInterfaceClient generator is not working but CURL is. That's not a big problem for me because this API is going to be read externally (from javascript calls) but I found it odd and maybe worth reporting, so here it goes:
I've reduced this to a reproducible case:
module app; import vibe.d;
import vibe.core.log;
@rootPathFromName
interface Api
{
@method(HTTPMethod.GET) @path("something/")
string getSomething(string id);
}
class ApiImpl: Api
{
override:
string getSomething(string id)
{
return "hello word";
}
}
shared static this()
{
setLogLevel(LogLevel.debugV);
auto router = new URLRouter;
router.registerRestInterface(new ApiImpl);
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["127.0.0.1"];
listenHTTP(settings, router);
}
unittest
{
auto apiClient = new RestInterfaceClient!Api("http://127.0.0.1:8080");
auto conv1 = apiClient.getSomething("someid");
}
If I use curl to do:
curl -X GET -H "Content-Type: application/json" "http://localhost:8080/api/someid/something/"
It returns the "hello world" as expected. But if I do a dub test
, Vibed shows this 404 where you can see that the URL call miss the :id argument:
no route match: ==>GET /api/something/<==<br>No response written for /api/something/<br>REST call: GET http://127.0.0.1:8080/api/something/ -> 404, 404<br>Error while handling response: vibe.web.common.RestException@../../../../../../.dub/packages/vibe-d-master/source/vibe/web/rest.d(377): Not Found (404)
Adding more arguments to getSomething other than an id works if I pass them in the URL with the ?key=value&anotherkey=anothervalue format.