用于构buildAPI的JavaScript文件

我想build立一个API。 我的应用程序是一个meteor/ nodejs应用程序。 所以我在api.js中创build了一个api.js文件:

 document.write({ example: 'Lorem ipsum' }); 

我希望通过调用localhost:3000/api.js来获取对象作为输出,但是我却看到了源代码。

第二个问题:

我如何处理参数? 例如localhost:3000/api.js?type=article

 const type = get[type]; // should be 'article' in this example 

使用路线将呈现HTML内容,但我需要输出纯JSON内容…

Meteor的工作方式是不同的,你不用做document.write,你用模板做事情。

为了提供一个API,你可以使用一个包,如Restivus https://atmospherejs.com/nimble/restivus

这将允许您非常容易地创build一个适当构build的API,并提取所需的URL参数。