On Sunday, 23 July 2017 at 15:23:25 UTC, holo wrote:
Hello
Im trying to create REST api for my simple web page. My code is
looking like below:
module service.frontpage;
import vibe.d;
@path("/api")
interface IFrontPageAPI
{
Json getHome();
}
class FrontPageAPI : IFrontPageAPI
{
this(auto tmp)
{
auto collect = tmp;
}
Json getHome()
{
logInfo("Getting HomePage from DB");
Bson query = Bson(["_id" : Bson("homepage")]);
auto result = collect.find(query);
logInfo("Iterating results...");
foreach (i, doc; result.byPair)
logInfo("Item %d: %s", i, doc.toJson().toString());
return result.toJson();
}
}
But when i try to compile it im getting:
source/service/frontpage.d(15,3): Error: undefined identifier
'tmp', did you mean alias 'cmp'?
Did i miss something?
You need to
- use Class variables
- use types instead auto (here Mongo collection)
- return a proper Json
Have a look at: https://is.gd/7AMsKs
And play with it - no output means no complication error.