strapiurl-parameters

Retrieve url param value from strapi


How do I get the parameters value passed in the url? For example, my url is /forgot-password?email=testing@example.com&token=fb49d692186dd4744af50446fad2f031

I want to get the value of email and token. All I found from the doc is only about the segment as parameters value which set from route as /user/:id which is different usage for my case.


Solution

  • Strapi uses koa.
    Therefor you can just use ctx.request.query inside your handler:

    async test(ctx) {
      const queryObj = ctx.request.query
      //use them...
    }
    

    For your stated request the object will contain:

    {
      email: 'testing@example.com',
      token: 'fb49d692186dd4744af50446fad2f031'
    }