Genie Discord forum

Author Avatarlyonsquark
11/21/2022, 8:33:51 PM

I'm using the new framework (e.g. @page...). Is there a way to access query parameters? For example, if I have a dashboard.jl file, and within I have

@page("/people", "people.ui.jl")

and I request this page with https://localhost:8000/people?lastname=Smith&firstname=Bob

Is there a way to access those query parameters (e.g. so that UI elements are filled in from a database lookup with that name) from within dashboard.jl ?

Thanks!!

Author Avatarlyonsquark
11/21/2022, 9:01:04 PM

Right - that works for POST, but doesn't seem to work for GET

Author AvatarMav
11/24/2022, 3:36:20 AM

As @Pere pointed out, have you tried using getpayload?

Author Avatarabhimanyuaryan
11/26/2022, 5:52:16 PM
params(:name_of_query_params)
Author Avatarlyonsquark
11/28/2022, 4:13:17 PM

Thanks - all of those answers are good, but don't fit my problem. Using the new framework (e.g. @page("ui.jl.html") ) , functions from the model don't see getparameters (just gets an empty dictionary). But, if I call a function from the UI page, like ``` <% reportText(Genie.Requests.getpayload()) %>

then I can pass in the query parameters and do something with them. The `reportText` function is defined in the model Julia file.
Author Avataressenciary
11/29/2022, 11:51:41 AM

@lyonsquark good question

Author Avataressenciary
11/29/2022, 11:53:25 AM

it's important to keep in mind that the app has multiple "stages" - the initial one is when the page is rendered in the browser, sending the HTML from the view, injecting the necessary JS files, and setting up the websocket connection to the backend. This is the request that has the GET params

Author Avataressenciary
11/29/2022, 11:54:00 AM

beyond this point, the data sync for the reactivity is done over websockets, using different requests

Author Avataressenciary
11/29/2022, 11:54:09 AM

these requests do not have the GET params

Author Avataressenciary
11/29/2022, 11:55:21 AM

so the subsequent requests after the page is loaded are over websockets and different from the original request

Author Avataressenciary
11/29/2022, 12:19:03 PM

so you need to capture the params from the initial page request - so you can use them later on

Author Avataressenciary
11/29/2022, 12:19:16 PM

you can store them in a private var

Author Avataressenciary
11/29/2022, 12:31:25 PM

(well, best to store just params()[:GET] to use less memory

Author Avataressenciary
11/29/2022, 4:52:24 PM

mmm... sorry, scrap that, it doesn't work reliably

Author Avataressenciary
11/29/2022, 4:52:28 PM

I think it worked by accident

Author Avataressenciary
11/29/2022, 4:52:32 PM

I need to dig some more

Author Avataressenciary
11/29/2022, 7:32:39 PM

ok, this is the best I could come up with

Author Avatarlyonsquark
11/30/2022, 5:20:47 AM

Thanks @essenciary - I'm actually making a dynamic page (it's a report), so simply doing <% makeReport(getpayload()) %> works great. But, I do have some form pages that I would like pre-filled in based on the URL query parameters, so I'll try that for those pages. Thanks again!