1

我正在尝试为我的简单 REST API 生成 JS,例如此处所述:doc。我的示例代码:

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

和界面:

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

一切都在编译没有任何问题,但我无法在任何地方找到生成的 JS。我在找错地方了吗 - 应用程序项目的主树?

4

1 回答 1

0

我在 vibed IRC 频道上获得帮助。有一个“处理”生成的 JS 数据的附加程序。在我们生成它之后,我们需要手动将其保存到文件中,下面的工作示例:

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();
}
于 2017-08-23T21:10:38.533 回答