node-erest
Easy to build api server depend on express. Easy to write, easy to test, easy to generate document. Install$ npm install erest --save Use yeoman generator$ npm install generator-erest -g# Express$ yo erest:express# erest$ yo erest:lei-web How to use'use strict';const API = require('erest').default;// API info for documentconst INFO = { title: 'erest-demo', description: 'Easy to write, easy to test, easy to generate document.', version: new Date(), host: 'http://127.0.0.1:3000', basePath: '/api',};// API group infoconst GROUPS = { Index: '首页',};// Init APIconst apiService = new API({ info: INFO, groups: GROUPS,});apiService.api.get('/index') .group('Index') .title('Test api') .register((req, res) => { res.end('Hello, API Framework Index'); });const express = require('express');const app = express();const router = new express.Router();app.use('/api', router);// bing express routerapiService.bindRouter(router, apiService.checkerExpress);app.listen(3000, function () { console.log('erest-demo listening started');}); |
请发表评论