Search code examples
koakoa-router

How can i get the 'id' when i want to match url like ''/index?id=xxx'' in koa-router


How can i get the 'id' when i want to match url like '/index?id=xxx' in koa-router? most articles on the web usually use url lick '/index/:id',but the back-end interfaces are not the case.


Solution

  • It does work the same on a back-end API, when you make a GET request to a web server it parses the query-string and uses the values to give you the intended response.

    When handling a GET request using koa-router you can specify the query string, such as '/index/:id', and to consume the value in your code you would simply do

    var id = ctx.request.query.id;