0

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.

Albin Liao
  • 35
  • 1
  • 1
  • 4

1 Answers1

0

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;

Qyaffer
  • 218
  • 2
  • 7