如何在sails.js中命名我的api,如/ api / v1?

问题描述:

我想将我的api请求命名为/ api / v1 /也许稍后也会将其命名为api / v2 /。我怎样才能在sails.js中有效地做到这一点?

I want to namespace my api requests to /api/v1/ Maybe later some also to api/v2/. How can I do this efficiently in sails.js?

有三种方法可以做到这一点。

There is three ways of doing this.

1st:blueprints

1st: blueprints

http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.blueprints.html
如何在帆中创建全局路线前缀?

prefix: '/api'

restPrefix:'/ api'

如何在帆中创建全局路线前缀?

第二:在每个控制器中添加

2nd: in each controller adding

_config: { prefix: '/api/v2' }

第3名:配置它在路线中

3rd: configure it in the routes

http: //sailsjs.org/#!/documentation/concepts/Routes

'/api/v2/': 'FooController',