如何在sails.js中命名我的api,如/ api / v1? [英] How do I namespace my api in sails.js like so /api/v1?

查看:120
本文介绍了如何在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',

这篇关于如何在sails.js中命名我的api,如/ api / v1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆