I'm using koa-router.
How can I get the request's query string params?
This is the best I managed to write:
import koaRouter from 'koa-router'; const router = koaRouter({ prefix: '/courses' }); router.get('/', async (ctx) => { console.log(ctx.qs["lecturer"]); });
but qs
is undefined
Any help will be profoundly appreciated!
The query parameter is the variable whose value is passed in the URL in the form of key-value pair at the end of the URL after a question mark (?). For example, www.geeksforgeeks.org? name=abc where, 'name' is the key of query parameter whose value is 'abc'.
Query strings are used to retrieve information from the URL of pages, which can then be utilized for further functioning of the web application functionalities. Client-side also has its own set of helper methods and properties to help developers with that.
According to the docs there should be a ctx.request.query
that is the query string items represented as an object.
You can use ctx.query
(or long-hand ctx.request.query
)
app.use( (ctx) => console.log(ctx.query) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With