Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anyway to access an object for query parameters and url parameters? #218

Closed
OultimoCoder opened this issue May 11, 2022 · 2 comments
Closed

Comments

@OultimoCoder
Copy link

I know you can access all the parameters in a url, www.url.com/?param1=hey&param2=three, by doing:

c.req.query('param1')
c.req.query('param2')

But is there anyway of just accessing an object for all the available parameters without having to know their names in advance?

@yusukebe
Copy link
Member

Hi @OultimoCoder

Make URL object from c.req.url and you can get searchParams. Do like this:

app.get('/', (c) => {
  const searchParams = new URL(c.req.url).searchParams
  for (const [key, value] of searchParams) {
    console.log(`${key} : ${value}`)
  }
  return c.text('/')
})

@yusukebe
Copy link
Member

Close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants