Vibe.d - Can not generate JS script for rest api

459 Views Asked by At

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?

1

There are 1 best solutions below

0
user3069488 On

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