-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API overhaul (comments welcome) #15
Comments
Hi, And if headers could be a function w/ state as param, this would give much more flexibility to api middleware. |
Nice work on the As @seokgyo pointed out, it could be useful to have access to state in headers. |
@seokgyo @lraivio Thanks for your input. I've given If you check out the In order to accommodate waiting for promises returned by custom I'll get to work on those tests soon, but I thought I would share with you what I have done in the last couple of days. You may even detect errors in the code just by looking at it... |
After working on implementing what I set out to do in the I had to change several things:
Please let me know if you find any bugs, or if you fundamentally disagree with any of my design decisions. |
Hey @agraboso, thanks for taking the lead on this middleware. Quick question regarding a new API, do you have any thoughts on how requests can be cancelled (aborted) and how to incorperate middleware for apply common business logic before requests are sent / when a request completes (for example, doing the OAuth Grant dance when the Access Token expires). |
@jonnyreeves Requests cannot be cancelled: the With respect to the OAuth Grant dance: if your token is expired, the server should respond with a 401 status, which would result in a failure FSA. I haven't given any thought to how to get a refresh token and reissue the request... (see #2 though) |
Thanks for producing this. I noticed that the requestType action doesn't get emitted until the fetch completes in the new API. Also perhaps it should emit the failureType in the catch. Maybe it should be?:
|
@agraboso, I'm having trouble getting my head around how a refresh flow would be implemented in redux, in my mind:
The main issue I'm having is how can the observer / new piece of middleware replay the original request - it will not have access to the original FSAA. Any thoughts would be greatly appreciated. |
@jonnyreeves: you can specify a custom Maybe you should do so only in case |
@grahamlyus: you're right, the request FSA should be emitted right before calling About changing the type of the FSA in the This extra complexity still made some sense because I thought In summary, I'm proposing this:
The upside is that failure FSAs are clearly delimited to server responses outside of the 200 range. The downside is the possibility of two request FSAs being dispatched — but I don't think that'd make reasoning about At the end of the day, I'm left with the feeling that |
Thanks for the response. I'm still pretty new to React/Redux. I noticed the issue whilst trying to figure out how to show a global Spinner component whilst Signing In via an API. I'm not sure of my approach, but I ended up creating additional middleware to check the The possibility of dispatching the
It doesn't quite feel right to me, I feel my previous version, using axios is easier to understand, although (apologies) this may now be getting a bit OT:
|
@grahamlyus The duplication of request FSAs is easy to reason about: you get at most one with an It seems you might want to show your spinner on a non-error request FSA, and hide it on an error request FSA—but then again I might be misunderstanding your code (after all, I don't know what I'm happy to keep talking about your issue, but I feel it might be outside of the realm of |
@grahamlyus Another thing you made me realize is that custom |
@agraboso Glad I was of some help ;) |
@grahamlyus Oh, now I see what you are doing. Indeed, a side effect in a a custom |
Thank you so much for this overhaul of the middleware @agraboso it's exactly what I needed. Your documentation is extremely clear, and your type descriptor design is very elegant. I had built a number of screens in my app which all needed normalizr, which worked fine with custom middleware based on the CALL_API from Redux examples. But then of course I needed to call on data which was a bit more freeform, which would have meant duplicating a large percentage of the plumbing into another middleware... yuck. This middleware allowed me to easily create custom type descriptors to normalize responses, and now I should easily be able to pull in the other data without the normalize step. While I was there I also fixed up a lot of my Flux actions which didn't conform to the FSA spec, so I learnt something there too. :) Keep up the good work, I really appreciate it :) |
Is the project currently still under maintained? |
@riophae: I haven't abandoned it, though I admit it might look like it: I have been very busy the last couple of months. I hope to be able to devote some time to |
@agraboso Excited to hear that. Keep up the awesome work! |
Closing: v1.0.0 is now out. If you would like any lingering ideas from this thread to be considered for a future version, please open an issue (or, even better, submit a PR) specific to it. |
Hi! Any example on this? I´m trying to add redux-refresh-token to your middleware but the code is quite old and doesn´t work fine. |
For a while now I've been thinking about a relatively major overhaul of
redux-api-middleware
. Time and again, people have expressed their need for extracting different kinds of data from server responses, and processing them differently (see #4, #9, #10, #13). The original source of the code in this module, thereal-world
example in theredux
repository, was probably though by Dan Abramov in the restrictive setting of exactly what he wanted to do in that example, and not in terms of how it could accommodate the needs of a large cross-section of the developers usingredux
.I've just pushed a new branch to
redux-api-middleware
namednext
. As of now, the only new thing is theREADME
. I've spent some time trying to come up with a schema that is not only flexible (allowing for the kind of access to server responses that people have asked for, and might ask for in the future), but also robust (in the sense of being able to deal with errors precisely and predictably), and thatREADME
is what I've come up with.I haven't started writing code implementing the changes outlined there — I hope to start doing so in the next few days. For the moment, I'd love to get input from those of you that have been using (or playing with)
redux-api-middleware
, to see if this rethinking of the API suits your needs.It's late already today, but I'll try to write another post tomorrow detailing some of the most important changes and why I went for them. Just giving everybody a heads up in the meantime — after all, I put quite a lot of effort into the
README
itself.cc @svnlto @seokgyo @lraivio @mohanzhang @eventhough @RanzQ @vdemin @latentflip
The text was updated successfully, but these errors were encountered: