Tag: apidevise

洞悉两个REST APIdevise的可行性

过去我已经开发了几个REST API,目前正在为我们公司内部的软件解决scheme构build一个新的REST API。 我select了MEAN堆栈来构build这个和Mongoose来pipe理模式devise和数据层validation。 良好的devise,耐用性和可扩展性是我的榜单之首。 API将被我们内部的Angular应用程序,Android应用程序所使用,谁知道还有什么,有一天我们的PHP网站可能会使用API​​,或者将来我们可能会为其他业务提供平台。 我目前正在称重两种devise: 通用目的 :根据身份validation提供对除API的受限制CRUD访问权以外的所有访问权限,为复杂请求提供自定义端点。 有点像Parse 。 限制 :曾经使用过这个。 API消费者提出了一个需求,然后由服务器以端点的forms完成。 通用devise API消费者可以灵活地根据前端需求来制作查询,而非常复杂的编译则被转移到自定义的端点上。 全局限制(例如:最多可以返回100条logging),每个经过身份validation的系统用户types可以是限制性模式和logging级访问。 'use strict'; module.exports = function (app) { // Api routing var api = require('../controllers/api.controller.js'); /** * Cental API router */ app.route('/api/create') .post(api.create); app.route('/api/read') .get(api.read); app.route('/api/update') .put(api.update); app.route('/api/remove') .delete(api.remove); app.route('/api/dashboard/:country/:date') //Complex endpoint .get(api.dashboard); }; 创build调用的示例响应: { "response":[ { "_id":"54f703531c3757fe23923250", […]

柴没有达到.end()

我正在使用摩卡和柴来testing我的节点/快递API,我不明白为什么testing没有达到.end() 这是testing: it('should authenticate successfully with user credentials', function (done) { agent .post('/login') .set('Content-Type', 'application/x-www-form-urlencoded') .send({ 'username': 'username', 'password': 'password'}) .end(function (err, res) { console.log(res); console.log('***************************Authenticated*********************************************'); expect(res).to.have.status(200); }); done(); }); 这里是我打的路线: app.post('/login', passport.authenticate('ldapauth', { successRedirect: '/' })); 我想我的问题可能是事实上没有正式的回应,而是一个redirect,但我不知道如何处理它。

在完成API Nodejs之前提示用户警告

这是用例: 用户调用一个API。 API发现它覆盖了以前保存的内容。 为了提前完成,用户需要说“是,覆盖”或“否,不覆盖”。 所以基本上需要一种方式来发回应答,并得到用户select的请求,然后继续操作。 我的顾虑是: 这样做的最佳做法是什么? 如果我休会服务并根据需要返回响应。 用户inputselect后是否需要激活相同的API? 我正在使用Nodejs / Express和Angularjs。