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:
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:
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:
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
I think I'm overthinking this / don't really know how, so I'd appreciate some fresh perspectives on this
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
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
but your task is to redirect to the correct website, right?
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?
send the data in the query
And why that over browser storage?
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
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?
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
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?
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
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
well, it's easier than you could imagine
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
that will be a mess
Yup my theory is that they intentionally don't have good documentation so you go to them to do custom development
that is horrible