Fork me on GitHub
#re-frame
<
2023-11-27
>
Nundrum23:11:05

I just wanted to check my understanding here. If I have an API with a bunch of endpoints to fetch, I'll need to register an event for each endpoint, and a matching event to handle the response for each endpoint? Perhaps with a error handling event for each. Or is it more common to put a smaller set of events in front of the API and pass more parameters when dispatching events?

wevrem23:11:51

You could register an event for each endpoint, or you could go to the other extreme and have a single event with some parameters to reach all the endpoints. I’m a sample of one, and I have no authority to say what is “common practice”, but I don’t do either of those options. My api call is registered as an effect that occurs as part of a bundle of related things that need to be done when handling an event. The events themselves are not modeled after the API, they are modeled on what kinds of things will happen in the app, like “user clicked on this link” or “this page loaded” or (trickier) “user did a hard reload and now all the fetches are going to happen in a random order, good luck”. Maybe mine isn’t a very good design, but your question made me realize that if someone looked at a list of my events, it would give them a good idea of the front-end functionality, but it wouldn’t help very much understanding the backend API.