Skip to content

feat: Add basic middleware functionality#677

Closed
Richienb wants to merge 2 commits into3.xfrom
middleware
Closed

feat: Add basic middleware functionality#677
Richienb wants to merge 2 commits into3.xfrom
middleware

Conversation

@Richienb
Copy link
Copy Markdown
Member

This PR adds basic middleware functionality. I'm not sure how to test this.

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
@Richienb Richienb requested review from bitinn and xxczaki September 21, 2019 09:17
@bitinn
Copy link
Copy Markdown
Collaborator

bitinn commented Sep 21, 2019

Tests are needed to demonstrate why this feature is needed. I need to know the use case for this to be honest.

@Richienb
Copy link
Copy Markdown
Member Author

Tests are needed to demonstrate why this feature is needed. I need to know the use case for this to be honest.

@bitinn There's a use case explained here: #668 (comment)

Copy link
Copy Markdown
Collaborator

@bitinn bitinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe we have reached a consensus on middleware design, so putting this on hold

@xxczaki xxczaki mentioned this pull request Sep 21, 2019
35 tasks
@jimmywarting
Copy link
Copy Markdown
Collaborator

jimmywarting commented Sep 22, 2019

Before doing something like this i would want to start on crating a constructor to get a new fetch instance that don't conflict with others middleware hooks

new FetchInstance()

@gdoron
Copy link
Copy Markdown

gdoron commented Oct 9, 2019

Also useful for using automatic follow redirect but in the end get all the redirect that there were in the middle.
That's the use-case for me.

@JefferyHus
Copy link
Copy Markdown
Member

This is more of hooks and not a middle-ware design. To be honest I don't see a reason why would someone need such things when it comes to sending requests, then comes the after hook which is imo is useless, fetch returns a promise so you already can execute things after fulfilling your request.

@LinusU
Copy link
Copy Markdown
Member

LinusU commented May 26, 2020

I agree with @JefferyHus, and would like to add that I think that global hooks like this are quite messy. If someone uses this to e.g. parse errors returned from an api, it can easy interfere with any other responses being returned from other parts of the code...

Also, should we really add features that aren't present in the official fetch specification? 🤔

@xxczaki
Copy link
Copy Markdown
Member

xxczaki commented May 26, 2020

Also, should we really add features that aren't present in the official fetch specification? 🤔

@LinusU The main reason why we want to introduce a middleware functionality/hooks is to allow users to set up things like caching/cookies, which are in the spec, but can't be added to node-fetch in an unopinionated way.

@Richienb
Copy link
Copy Markdown
Member Author

We can allow the consumer to specify separate hooks as an option like from got.

@LinusU
Copy link
Copy Markdown
Member

LinusU commented May 26, 2020

@xxczaki thanks for the clarification, I still think that it shouldn't be global though. I think that gots approach is quite good!

@xxczaki
Copy link
Copy Markdown
Member

xxczaki commented May 26, 2020

@LinusU Yeah, I also really like got hooks and I think we can take some inspiration from them.

@jimmywarting
Copy link
Copy Markdown
Collaborator

This PR have been idle for to long (created 2019) and never merged and perhaps outdated as well?. with some consideration i think FetchEvent #370 is better suited - so closing this...

@jimmywarting jimmywarting deleted the middleware branch January 25, 2022 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants