ysmood / nokit

A light weight set of handy tools for real world program.
51 stars 6 forks source link

A route DSL sugar middleware for noflow #10

Open ysmood opened 9 years ago

ysmood commented 9 years ago

Such as

let http = require('http');
let { route, flow } = kit.proxy;

route
  .get('/items', ctx => ctx.body = [1, 2, 3])
  .post('/upload', uploader)
  .error(errorHanlder)
.end();

http.createServer(flow(route)).listen(8080);

@magnus-

magnus- commented 9 years ago

I prefer to apply the DSL as illustrated below:

// acquire an instance of verbalizer
var I = verbalizer();

// GET /getUserInfo
// method getUserInfo can injected within global scope
I.get.an.instance.of('UserInfo').by.method('getUserInfo')
    .with.arguments.schema('SchemaUser')
    .when.arguments.error('status 400').with.comment('input argument invalid')

The syntax of the verbalizer can be discussed later

ysmood commented 9 years ago

A good point to start.

ysmood commented 9 years ago

So what's your plan to implement it?

magnus- commented 9 years ago

I’ll take several days to weave the syntax tree and to determinate words category. Besides, words for different purpose usage can be gathered into different categories, which you could reckon them as normal English grammatical categories something like conjunction or predicate.

And what matters most will be the customization of the injection and error handling.

The essentiality of the Verbalizer is to promote user with straightforward syntax-bound words to documentize their logic behavior.

magnus- commented 9 years ago

Additionally, Verbalizer should stick to express or other middle-ware based frameworks as well. What do u think? @ysmood

ysmood commented 9 years ago

For now, I don't have any better idea than yours. Looking forward to your code.