0

I'm trying to create simple REST api, but when i try to compile my code im getting

frontpage.d(15,3): Error: undefined identifier 'tmp', did you mean alias 'cmp'?

Here is my code:

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();
  }
}

Can someone help me with it? tmp is temporary variable to pass mongoDB collection handler.

user3069488
  • 75
  • 1
  • 6

1 Answers1

2

Same answer as on DLearn.

You need to - use Class variables - use types instead auto (here Mongo collection) - return a proper Json

Have a look at this interactive example - and feel free to play with it. No output means no compilation error.

greenify
  • 1,127
  • 8
  • 7
  • 1
    Thank you it solves my problem but right now im getting another error (described under DLearn link which you attached) – user3069488 Jul 23 '17 at 16:41