Skip to content
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

refactor(http): remove callbacks, simplify options normalization and export only one function #347

Merged
merged 11 commits into from
Jan 10, 2022

Conversation

pablopalacios
Copy link
Contributor

Summary of changes:

  • replace get and post with only one method:httpRequest
  • httpRequest always returns a promise (fetcher is now the only responsible for handling the callback flow)
  • Simplify http request options normalization

Again, I recommend you to review commit by commit ;)

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@redonkulus redonkulus self-requested a review January 5, 2022 15:27
@redonkulus
Copy link
Contributor

@pablopalacios is this part of the 1.0 breaking changes / api refactor work?

@redonkulus
Copy link
Contributor

Looking at the code, I wonder if we should just remove all the .then() calls and switch to async / await everywhere. Especially if we are removing callbacks. Its much easier to maintain and read. Then we can just document that this library only works with latest browsers and node versions.

@@ -128,11 +128,11 @@ Request.prototype._captureMetaAndStats = function (err, result) {
Request.prototype.end = function (callback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This callback is still required?

var baseUrl = config.uri;
if (!baseUrl) {
baseUrl = config.cors
? request.options.corsPath
: request.options.xhrPath;
}

if (request.operation === OP_READ) {
if (request.operation === OP_READ && !config.post_for_read) {
Copy link
Contributor

Choose a reason for hiding this comment

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

post for read is weird, I know this is old, what is the use case for this again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be really honest, I don't know. I see in my code base that we used to use create instead of read just to make sure we would have a POST. I think the reason for that was related to how our bot protection used to work. In that case, calling read with post_for_read would be semantically better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By the way, I checked that the support exists since the very first implementation. Don't you have any usage of it in your code base?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was always under the impression that POST = create and GET = read, I'm not really sure of all the different usage of fetchr internally, we have many different apps using it.

@pablopalacios
Copy link
Contributor Author

@pablopalacios is this part of the 1.0 breaking changes / api refactor work?

Actually no (but it definitely will help). I've found some corner cases that are not being covered regarding aborts, timeouts and retries. But in order to fix it, the http module must be simplified first. So before any breaking change, I would like to tidy up the internals and have http working 100%.

Looking at the code, I wonder if we should just remove all the .then() calls and switch to async / await everywhere. Especially if we are removing callbacks. Its much easier to maintain and read. Then we can just document that this library only works with latest browsers and node versions.

I'm not so sure if we can fully migrate to async/await. Since we have abort as part of the API, we must return something to the user before getting the response. But I think after tidying up the code, it will get easier to understand (even though I think doing a fetch-abort-retry-timeout will always end up in a not so straightforward code).

Copy link
Contributor

@redonkulus redonkulus left a comment

Choose a reason for hiding this comment

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

Changes look good to me, good to see more consolidation of code

@redonkulus redonkulus merged commit 1528c02 into yahoo:master Jan 10, 2022
@pablopalacios pablopalacios deleted the http-refactor branch July 23, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants