/** * 继承 koa 的 Context * @class Context * @see http://koajs.com/#context */ /** * 实现页面跳转 * @see Response#redirect * @method Context#redirect * @param {String} url 需要跳转的地址 */ /** * 开启 {@link Rest} 功能后,将会有 `this.params` 对象 * @member {Object} Context#params * @example * ##### ctx.params.id {String} * * 资源 id,如 `GET /api/users/1` => `'1'` * * ##### ctx.params.ids {Array} * * 一组资源 id,如 `GET /api/users/1,2,3` => `['1', '2', '3']` * * ##### ctx.params.fields {Array} * * 期待返回的资源字段,如 `GET /api/users/1?fields=name,title` => `['name', 'title']`. * 即使应用 Controller 实现返回了全部字段,[REST] 处理器会根据 `fields` 筛选只需要的字段。 * * ##### ctx.params.data {Object} * * 请求数据对象 * * ##### ctx.params.page {Number} * * 分页码,如 `GET /api/users?page=10` => `10` * * ##### ctx.params.per_page {Number} * * 每页资源数目,如 `GET /api/users?per_page=20` => `20` */ /** * 设置返回资源对象 * @member {Object} Context#data= * @example * ```js * ctx.data = { * id: 1, * name: 'fengmk2' * }; * ``` * * 会返回 200 响应 * * ```js * HTTP/1.1 200 OK * * { * "data": { * "id": 1, * "name": "fengmk2" * } * } * ``` */ /** * 设置 meta 响应数据 * @member {Object} Context#meta= * @example * ```js * ctx.meta = { * count: 100 * }; * * ctx.data = [ * { * id: 1, * title: 'post title 1' * }, * { * id: 2, * title: 'post title 2' * } * ]; * ``` * * 会返回 200 响应 * * ```js * HTTP/1.1 200 OK * * { * "meta": { * "count": 100 * } * "data": [ * { * "id": 1, * "title": 'post title 1' * }, * { * "id": 2, * "title": 'post title 2' * } * ] * } * ``` */