Architecture Question (not code specific)

I have this locations feature I'm working on implementing and I think I'm getting close to figuring it out but wondering on some architecture decisions. The way everything is set up now looks like this:
1) User enters their location (zip code) into an input field (custom web component) and hits enter
2) Custom web component makes a GET request to an endpoint and the endpoint does a SQL query and returns a URL with the correct page
3) Web component redirects to the URL returned from backend
1) User enters their location (zip code) into an input field (custom web component) and hits enter
2) Custom web component makes a GET request to an endpoint and the endpoint does a SQL query and returns a URL with the correct page
3) Web component redirects to the URL returned from backend
I need to retrofit this. Instead of returning a URL, I need the API to return JSON data of multiple offices AND redirect. Let's look at an easy example of data I could send back to the client:
{
"offices": {
"officeOne": { "location": "Philadelphia" },
"officeTwo": { "location": "Austin" },
}
}
{
"offices": {
"officeOne": { "location": "Philadelphia" },
"officeTwo": { "location": "Austin" },
}
}
My question is, what's the best way to accomplish sending JSON data to the client and redirecting? Should I include an object like this:
{
"offices": {
"officeOne": { "location": "Philadelphia" },
"officeTwo": { "location": "Austin" }
},
"redirectUrl": "https://redirectedpage.com"
}
{
"offices": {
"officeOne": { "location": "Philadelphia" },
"officeTwo": { "location": "Austin" }
},
"redirectUrl": "https://redirectedpage.com"
}
And then put the office data into something like local/sessionStorage or should I put the office data in query parameters? Or am I completely off track and thinking about this wrong?
18 Replies
vince
vinceOP10mo ago
I think I'm overthinking this / don't really know how, so I'd appreciate some fresh perspectives on this
ἔρως
ἔρως10mo ago
you can just return the correct url, since the rest of the data is useless unless you want to show a splash screen to inform the person is going to be redirected
vince
vinceOP10mo ago
wym? I need to send the office data to the client and display it client-side We're using some mixture of Spring Boot & Handlebars so I think there's definitely a better way to do this server-side (without having to do this client-side) but I neither have the know-how for that nor the time so client-side is the straightest path forward
ἔρως
ἔρως10mo ago
but your task is to redirect to the correct website, right?
vince
vinceOP10mo ago
Sorry I should have clarified -- the redirected page is owned by our website. On that redirected page will be a custom component that will need to be aware of the office data and render it accordingly. My question is what is the best way to do this client-side: through query params or session / local storage -- or some other options I don't know of?
ἔρως
ἔρως10mo ago
send the data in the query
vince
vinceOP10mo ago
And why that over browser storage?
ἔρως
ἔρως10mo ago
anything can write anything there that means, you can have a conflict just imagine this: the localstorage is updated a few ms after you start loading the other page the page you expected to see won't be valid the data is gone and is not wrong
vince
vinceOP10mo ago
Not to be pedantic but I just really don't know -- can't the same thing be said for query params? Really, anything can change the url too right?
ἔρως
ἔρως10mo ago
no, it can't you can't change the query string from another tab you can change the localstorage in any tab including, but not limited to having it deleted
vince
vinceOP10mo ago
Ohhh I didn't know that but it makes sense. So you're saying hypothetically if I have a key called "offices" in my local storage, and somehow I visit another site that stores an "office" key, it'll be overwritten?
ἔρως
ἔρως10mo ago
yes and if the user deleted the data before the page loads, it will be gone the best way to pass state between 2 pages is with url parameters you can pass it in the hash string as well
vince
vinceOP10mo ago
I don't even know what that is but that's headache for another day 😂 Thank you Epic! I wish I didn't have to do this client-side and I could just leverage the codebase but alas
ἔρως
ἔρως10mo ago
well, it's easier than you could imagine
vince
vinceOP10mo ago
I don't doubt it but this feature is to be completed ASAP and there's 0 documentation about the codebase lol We already have a zip code lookup which was written by the people that authored the codebase and they used client-side for this (presumably because it's easier) so I've just been copying what they've been doing
ἔρως
ἔρως10mo ago
that will be a mess
vince
vinceOP10mo ago
Yup my theory is that they intentionally don't have good documentation so you go to them to do custom development
ἔρως
ἔρως10mo ago
that is horrible
Want results from more Discord servers?
Add your server