widgetti / solara

A Pure Python, React-style Framework for Scaling Your Jupyter and Web Apps
https://solara.dev
MIT License
1.62k stars 105 forks source link

question: does solara accept query parameters #469

Closed havok2063 closed 2 months ago

havok2063 commented 4 months ago

Does Solara accept query parameters in the url? I seem to recall that it does but I can't find anything referencing it in the documentation or examples of how to retrieve parameters from something like localhost:8765?param=a&param=b. Also related to #457

havok2063 commented 3 months ago

A follow-up question, does Solara provide access to the incoming request?

havok2063 commented 3 months ago

I finally found answer to my first question. For posterity, you can access get request query parameters through the router.search attribute. With a url like http://localhost/?a=b&hello=there, router.search returns a string of a=b&hello=there that can be parsed.

def Page():
        router = solara.use_router()
        params = router.search
        print(params)

I couldn't find any of accessing the complete request through the solara.server.fastapi.app, so that is still unknown. This would be useful for accessing request headers and cookies to extract out authentication info.

tharwan commented 2 months ago

Maybe this helps: https://solara.dev/api/cookies_headers

havok2063 commented 2 months ago

Yeah I believe this should work. I haven't had a chance yet to test it out but hopefully will soon.

maartenbreddels commented 2 months ago

Hi Florian,

thank you for beating me to this :)

I was looking for this issue, because I wanted to reply to Brian that this is released in version 1.27.

Let me know if you run into issues Brian, and I think we can close this issue.

Regards,

Maarten