How can I handle GET data in koa

117 Views Asked by At

I am newbie in koa, and I am using koa-router. For me, the code is like:

this.router.get('/user/test',function(){
            debugger;
        })

then I visit localhost:3000/user/test?p=1&q=2, I just find that there seems no method for me to get the value of p and q. So how can I quickly get the value?

1

There are 1 best solutions below

0
On BEST ANSWER
var route = require('koa-route');
var koa = require('koa');
var app = koa();

// /user/test/?a=1&b=2 -> will console log your values
app.use(route.get('/user/test', function* () {
  console.log(this.query.a)
  console.log(this.query.b)
}));