Node.js与Sails~自定义响应体responses
在Node.js里,你可以控制请求和响应,自己可以定义自己的响应方式,如对文本如何响应,对json如何响应,对图像流如何响应等等,而这些在Sails架构里,变得更加容易和清晰了,它位于项目的api/responses目录下,你可以定义自己的响应体。
其实sails为我们封装了一些标准的相应,如view方法,这也就是一种响应体,它可以将文本,json对象渲染到指定的视图上,而我们自己可以效仿它,实现自己的响应体,下面代码是官方给出的一个实例,它的方法名为myResponse,这是sails架构一个定义类模块的方式,即JS文件名不是你的类名,我们在程序里可以通过res.myResponse("你的响应内容")去调用它,具体代码如下
/**
* api/responses/myResponse.js
*
* This will be available in controllers as res.myResponse('foo');
*/ module.exports = function(message) { var req = this.req;
var res = this.res; var viewFilePath = 'mySpecialView';
var statusCode = 200; var result = {
status: statusCode
}; // Optional message
if (message) {
result.message = message;
} // If the user-agent wants a JSON response, send json
if (req.wantsJSON) {
return res.json(result, result.status);
} // Set status code and view locals
res.status(result.status);
for (var key in result) {
res.locals[key] = result[key];
}
// And render view
res.render(viewFilePath, result, function (err) {
// If the view doesn't exist, or an error occured, send json
if (err) {
return res.json(result, result.status);
} // Otherwise, serve the `views/mySpecialView.*` page
res.render(viewFilePath);
});
};
它实现了普通文件和json对象的两种响应方式,我们在代码里调用它和view类是一样的
module.exports={
index: function (req, res){
return res.view({title:"大叔",engTitle:"Lind"});
//return res.view("view_name",data)//view_name参数为空表示用当前的action
},
err:function(req,res){
return res.myResponse({errCode:0,error:"产生错误"});
} };
通过执行http://localhost:1337/test/err得到下面的结果
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAATQAAAEUCAIAAAAqT13+AAAfU0lEQVR4nO2d61db1533z7tZK+/nP+irWfOM1nqezqVP25k+M51Op23SyTRxmqZKU+fmkNiu69Tj2E2C7fii1InTOnVJYiAYY+MLcLgj7tjGBmPukkAgQEJCAiEJgS5c7LXO8+JIQue2dSQhtEHfz/otW5zL3vucsz/a+9y2GMfsFDlmbRaTabT7wYO2rjtNre21TS21TS2Nre1tX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NHUPG07XYh+0gDAbYo4XNCuxPICQClQE4AKAVyAkApkBMASoGcAFAK5ASAUiiSMxPvLwKwc6FITo7jOINOk4s3tACQgTI5OYNOi7YTAI6DnABQC+QEgFIgJwCUAjkBoBTa5ORY7fYOeQUArVAnJ8dxrBa3OwGgT07c6QSAhzY5cc4JQATICQClQE4AKAVyAkApkBMASqFMTlyrBSAKRXLifU4A4qFITgBAPJATAEqBnABQCuQEgFIgJwCUAjkBoBQlOXFfA4AsQ2o58UQAAFmE2K3Fs3QAZA/ICQClQE4AKAVyAkApkBMASiHf58Q4lQBkjYQPIWCcSgCyA1lO3OkEIGvgnBMASoGcAFAK5ASAUiAnAJQCOQGgFLyVAgCl4H1OACgFIyEAQCmQEwBKgZwAUArkBIBSICcAlAI5AaAUyAkApUBOACgFcgJAKZATAEqBnABQCuQEgFIgJwCUAjkBoBTICQClQE4AKAVyAkApkBMASoGcAFAK5ASAUiAnAJQCOQGgFMgJAKVATgAoBXICQCmQEwBKgZwAUArkBIBSICcAlAI5AaAUyAkApUBOACgFcgJAKZATAEqBnABQCuQEgFIgJwCUAjkBoBTICQClQE4AKAVyAkApkBMASoGcAFAK5ASAUiAnAJQCOQGgFMgJAKX8f+q1mdIZvvoiAAAAAElFTkSuQmCC" alt="" />
上面的功能类似于c# mvc里的重写ViewResult,都是对输出响应流进行控制的。
Node.js与Sails~自定义响应体responses的更多相关文章
- Node.js与Sails~项目结构与Mvc实现
回到目录 Sails是一个Node.js的中间件架构,帮助我们很方便的构建WEB应用程序,网址:http://www.sailsjs.org/,它主要是在Express框架的基础上发展起来的,扩展了新 ...
- Node.js与Sails~方法拦截器policies
回到目录 policies sails的方法拦截器类似于.net mvc里的Filter,即它可以作用在controller的action上,在服务器响应指定action之前,对这个action进行拦 ...
- Node.js之sails框架
先开一坑,有空更新,记录最近钉钉项目上对node及sails框架的学习记录和理解
- Node.js与Sails~日志机制log
回到目录 看到Sails的日志就会想起来log4net,确实它们在很多地方是相似的,都是采用分级别记录的方式,而sails我觉得在使用上更加方便,它不需要我们做多于的事情,直接sails.log.级别 ...
- Node.js与Sails~Model和ORM的持久化
回到目录 上一讲说了在sails里定义model及相关参数的说明,这一讲主要说一下如何将你的Model持久化到文件,关系数据库和Nosql数据库里,在持久化这点上,sails是统一管理的,它可以在/c ...
- Node.js与Sails~Model数据模型
回到目录 对于Sails来说,它的Model与数据库对应,不过它并没有采用目前比较流行的poco贫血模型,而是采用了类似DDD的充血模型,即它的数据实体里即有数据库字段(属性)而且还有方法,而模型里的 ...
- Node.js与Sails~中间查询语言Waterline
回到目录 上讲主要说了如何配置sails的持久化机制,这讲主要说一下实现持久化时的增删改查的语法,在sails里使用了和mongodb风格类似的waterline查询语言,使用简单,语法生动,下面我们 ...
- Node.js与Sails~redis组件的使用
有段时间没写关于NodeJs的文章了,今天也是为了解决高并发的问题,而想起了这个东西,IIS的站点在并发量达到200时有了一个瓶颈,于是想到了这个对高并发支持比较好的框架,nodeJs在我之前写出一些 ...
- Node.js中的自定义模块化
打造步骤: 1. 创建模块 [ Function / Object / String 2. 导出模块 - module.exports = 模块名称 导出一个 - module.exports = ...
随机推荐
- 产生NaN
1.数学运算失败 数字+undefind=NaN 2.数据类型转化失败产生NaN isNaN()检查 是不是一个有效数字,是NaN 返回 ture ,正常数字返回false.
- java获取文件名的三种方法
import java.io.File; import java.util.Arrays; public class FileName { /** * @param args */ public st ...
- web应用程序传递连接字符串给FastReport数据源
public static FastReport.Report fr = new FastReport.Report(); public static FastReport.EnvironmentSe ...
- 【Android UI】Android开发之View的几种布局方式及实践
引言 通过前面两篇: Android 开发之旅:又见Hello World! Android 开发之旅:深入分析布局文件&又是“Hello World!” 我们对Android应用程序运行原理 ...
- Java中将0x开头的十六进制字符串转换成十进制整数
1.Integer.toString(int i) 由于input(输入数据)是以0x开头的字符串,并不是整型.因而在用 String s = Integer.toString(input); 时用会 ...
- c++中的指针之指针在数组
使用一维指针数组输出一维数组中的数 int array[]={1,2,3,4,5,6}; int *p; p=array; for(int i=0;i<6;i++){ ...
- idea小技巧
1.不使用import *:Setting=>Editor=>Code Style=>Java=>Imports=>Class count to use/Names co ...
- Linux初记
ctrl+u可以在shell下删除行,如果此键不起作用,就试试ctrl+x ctrl+z可以将程序挂起,不会终止程序,但可以将程序挂起. 通过fg命令可再把此作业切换到前台 cp命令的目标文件如果是一 ...
- dom4j解析xml的增加信息
想要在xml中增加信息,那么就要先找到你要加信息的节点 前三行是固定模式,主要是找到xml文件的地址,并且得到根节点,再从根节点中便利出来movie的所有节点之后用集合接收 SAXReader rea ...
- SCRUM报告(1)
我们组的PM是白杰,团队SCRUM 报告如下: 一.第一次spring会议内容: 1.确定所做项目的方向: 2.将调查问卷的结果进行统计,做了需求分析,大致了解了用户的想法: 3.确定了团队计划bac ...