API开发神器-Postman

Postman helps you develop APIs faster. 豪华午餐 Postman 构建、管理、文档化API 在线安装 Chrome插件版 https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop MAC版 https://www.getpostman.com/app/postman-osx 离线安装 使用已经安装好的Postman文件夹,机器默认存放目录:/Library/Application\ Support/Google/Chrome/Default/Extensions 进入chrome://extensions/,选择Load unpacked extensions,加载Postman的文件夹 ...

June 24, 2016 · 5 min · Yuanjie

API自动化测试与持续集成

目的 如何使用SuperTest测试框架,进行API测试 如何将API测试与构建工具结合 如何将API测试、构建工具与持续集成结合 ...

May 10, 2016 · 4 min · Yuanjie

SuperTestWithGulp

Gulp Automate and enhance your workflow 用自动化构建工具增强你的工作流程! 官网:http://gulpjs.com/ 中文官网:http://www.gulpjs.com.cn/ 简体中文文档: https://github.com/lisposter/gulp-docs-zh-cn 安装npm install --global gulp 验证 ➜ Downloads gulp -v [15:59:38] CLI version 3.9.1 [15:59:38] Local version 3.9.1 ...

April 15, 2016 · 1 min · Yuanjie

Http-Header

Header 定义 提供HTTP所需要的信息或发送的信息 HTTP header fields provide required information about the request or response, or about the object sent in the message body. ...

February 29, 2016 · 3 min · Yuanjie

SuperTest-header:Auth设置

SuperTest SuperTest-API测试 Auth分类 Basic:基本身份认证,直接采用:用户名密码 基本用法 1 2 3 4 5 6 it('should receive a status code of 200 with login', function(done) { request(url) .get('/staging') .auth('the-username', 'the-password') .expect(200, done); }); Base64加密 1 .set("Authorization", "basic " + new Buffer("username:password").toString("base64")) Digest:摘要式身份认证 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 request.get('http://some.server.com/').auth('username', 'password', false); // or request.get('http://some.server.com/', { 'auth': { 'user': 'username', 'pass': 'password', 'sendImmediately': false } }); // or request.get('http://some.server.com/').auth(null, null, true, 'bearerToken'); // or request.get('http://some.server.com/', { 'auth': { 'bearer': 'bearerToken' } }); OAuth Authentication 例子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 var OAuth = require('openauth'); var request = require('superagent'); require('superagent-openauth')(request); var oauth = new OAuth(consumerKey, consumerSecret, {...}); request.post('https://api.twitter.com/1.1/statuses/update.json') .sign(oauth, token, tokenSecret) .type('urlencoded') .send({status: 'hello world'}) .end(function(res) { console.log(res.status, res.body); }); OAuth 1 1 request.sign(oauth, token, secret); oauth: OAuth instance token: string access token secret: string access token secret ...

February 28, 2016 · 1 min · Yuanjie

Node.js时间格式处理

moment库 专门用于Javascript的时间转化、验证、处理、展示 安装moment npm install moment 使用moment 引用moment 1 var moment = require('moment'); 转化时间 1 2 3 4 5 6 7 //将时间格式转化为:2016-01-22 21:21:26 moment(new Date()).format("YYYY-MM-DD HH:mm:ss"); moment().format('MMMM Do YYYY, h:mm:ss a'); // January 26th 2016, 10:25:00 pm moment().format('dddd'); // Tuesday moment().format("MMM Do YY"); // Jan 26th 16 moment().format('YYYY [escaped] YYYY'); // 2016 escaped 2016 moment().format(); // 2016-01-26T22:25:24+08:00 相对时间 1 2 3 4 5 moment("20111031", "YYYYMMDD").fromNow(); // 4 years ago moment("20120620", "YYYYMMDD").fromNow(); // 4 years ago moment().startOf('day').fromNow(); // a day ago moment().endOf('day').fromNow(); // in 2 hours moment().startOf('hour').fromNow(); 日历时间 1 2 3 4 5 6 7 8 moment().subtract(10, 'days').calendar(); // 01/16/2016 moment().subtract(6, 'days').calendar(); // Last Wednesday at 10:27 PM moment().subtract(3, 'days').calendar(); // Last Saturday at 10:27 PM moment().subtract(1, 'days').calendar(); // Yesterday at 10:27 PM moment().calendar(); // Today at 10:27 PM moment().add(1, 'days').calendar(); // Tomorrow at 10:27 PM moment().add(3, 'days').calendar(); // Friday at 10:27 PM moment().add(10, 'days').calendar(); 其它应用 1 2 3 4 5 6 7 8 moment().format('L'); // 01/26/2016 moment().format('l'); // 1/26/2016 moment().format('LL'); // January 26, 2016 moment().format('ll'); // Jan 26, 2016 moment().format('LLL'); // January 26, 2016 10:28 PM moment().format('lll'); // Jan 26, 2016 10:28 PM moment().format('LLLL'); // Tuesday, January 26, 2016 10:28 PM moment().format('llll'); 其它使用:官方文档 API测试应用:Node.js 日期判断、对比 日期格式转化

January 26, 2016 · 1 min · Yuanjie

Node.js调用数据库:Mysql

安装Mysql包 npm install mysql 调用 Mysql包 1 var mysql = require('mysql'); 数据库查询 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 var mysql = require('mysql'); var connection = mysql.createConnection({ host : '10.29.10.29', port : 3307, user : 'root', password : '', database : 'emall', //charset : 'UTF8_GENERAL_CI', debug : false }); connection.connect(); connection.query("use emall"); connection.query('select id from users', function(err,results) { if (err) { throw err; } }); connection.end(); 数据库插入 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 var mysql = require('mysql'); var connection = mysql.createConnection({ host : '10.29.10.29', port : 3307, user : 'root', password : '', database : 'emall', //charset : 'UTF8_GENERAL_CI', debug : false }); connection.connect(); connection.query("use emall"); var insertUser2 = "INSERT INTO `sms_verification_code` (`phone_number`, `code`) VALUES ('18392520000', '018227');"; connection.query(insertUser2,function(err,results,field){ if (err) { throw err; } }); connection.end(); API测试应用:Node.js 初始化数据 数据CRUD 获取部分无返回值的Post结果,如:查询创建用户后,获取用户的ID

January 26, 2016 · 1 min · Yuanjie

SuperTest-API测试

什么是SuperTest The motivation with this module is to provide a high-level abstraction for testing HTTP, while still allowing you to drop down to the lower-level API provided by super-agent. 简单说明:用来测试HTTP请求,提供简单的super-agent来实现API请求 安装SuperTest npm安装 官网下载对应的操作系统版本-NPM,下载完成后,直接进行安装即可 cnpm,若翻墙网络比较慢或访问不了的话,可以尝试使用cnpm(国内的镜像)。CNPM SuperTest安装 npm install supertest --save-dev grunt安装 npm install -g grunt-cli 使用Grunt来管理和运行SuperTest Git Clone SuperTestDemo。此项目针对访问的URL的返回状态进行验证。 ...

January 17, 2016 · 2 min · Yuanjie