1

I'm trying to generate JS for my simple REST API like eg described here: doc. My example code:

import vibe.d;
import wbapi;
import std.array : appender;
import vibe.core.file;

void main()
{
  // generate JS for access
  auto test = appender!string;
  auto settingsJS = new RestInterfaceSettings;

  settingsJS.baseURL = URL("http://localhost/api/integration/");
  generateRestJSClient!IfWhiteBlowerAPI(test, settingsJS);
}

and interface:

    @path("/api/integration")
    interface IfWhiteBlowerAPI
    {
        Json get();
        string postDeaf(Json obj);
    }

Everything is compiling without any problem but i can't find generated JS anywhere. Am i looking in wrong place - main tree of app project?

user3069488
  • 75
  • 1
  • 6
  • Have you run the resulting executable? The generation would happen at runtime (D's CTFE can't write to the filesystem). – eco Aug 23 '17 at 18:47
  • Yes, im building it with dub and it is automatically run after build. I try to start it manually too, but with same effect.. no js file. – user3069488 Aug 23 '17 at 20:10

1 Answers1

0

I get help on vibed IRC channel. There is appender which is "handling" generated JS data. After we generate it we need to save it to file manually, below working example:

import vibe.d;
import std.stdio;
import std.array : appender;
import vibe.core.file;

@path("/api/integration")
interface IfWhiteBlowerAPI
{
    Json get();
    string postDeaf(Json obj);
}

void main()
{
  // generate JS for access
  auto test = appender!string;
  auto settingsJS = new RestInterfaceSettings;

  settingsJS.baseURL = URL("http://localhost/api/integration/");
  generateRestJSClient!IfWhiteBlowerAPI(test, settingsJS);

  auto f = File("test.js", "w");
  f.write(test.data);
  f.close();
}
user3069488
  • 75
  • 1
  • 6