-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
框架支持RESTFUL风格的接口 #102
Comments
现在的框架不是为 RESTful 后端设计的,是针对我们自己部门的后端框架的。 |
哦,我们现在想用这个框架,但是同时想支持后端同学的RESTful接口,有没有办法通过hook的方法或者其他来支持呢? |
改一改 serverIO ? |
@yibuyisheng 主要吧,restful接口地址是动态的,所以common下面那个apiconfig就有些问题了 |
io.request(realURL, data, {method: method});
// 代入运行时参数可能是:
io.request('/data/user/10086', {}, {method: 'GET'});
// 或者
io.request('/data/user/create', {name: 'Steve'}, {method: 'PUT'}); 这样在业务代码里可以还按现有的逻辑来写: model.requestUser({id: '10086'}).then(function (data) {
// handle data
}); |
感谢 @Justineo 大神的指导 request.post = function (path, data, options) {
options = options ? options : {};
u.extend(options, {method:'POST'});
var realUrl = handlerUrl(url, path);
return io.request(realUrl, data, options);
};
request.put = function (path, data, options) {
options = options ? options : {};
u.extend(options, {method:'PUT'});
var realUrl = handlerUrl(url, path);
return io.request(realUrl, data, options);
}; 在config里面URL定义是这样 |
现在框架里面的API都需要通过提前定义而且只支持get和post的方法,如何支持put和delete以及动态路由呢?
The text was updated successfully, but these errors were encountered: