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

[Feature suggestion] Ability to inject the HTTP client #60

Open
sarahdayan opened this issue Jun 22, 2023 · 0 comments · May be fixed by #61
Open

[Feature suggestion] Ability to inject the HTTP client #60

sarahdayan opened this issue Jun 22, 2023 · 0 comments · May be fixed by #61

Comments

@sarahdayan
Copy link

sarahdayan commented Jun 22, 2023

Hey! Thanks a lot for this great library 🙂 I'm using it in a production project already, and currently implementing it in another.

I think one great improvement would be to allow passing a custom HTTP client in case you don't want to use Axios. This can be super helpful if you're using a custom client with added features such as deduping, caching, etc. For example, I'm currently working with Next.js and React Server Components, and the recommended way to fetch data only once server-side is to use a monkey-patched fetch client that caches requests forever.

The API could look something like this (here, using window.fetch):

import { parse } from 'rss-to-json';

const client = (url: string) => fetch(url).then((r) => r.text()).then((data) => ({ data }));

(async () => {
  const rss = await parse('https://blog.ethereum.org/feed.xml', client);

  console.log(JSON.stringify(rss, null, 3));
})();

I know the parse function currently takes Axios options as its second argument, but this can be circumvented by simply checking the type (object vs. function).

If you're open to this feature, check my PR 🙂

@sarahdayan sarahdayan linked a pull request Jun 22, 2023 that will close this issue
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 a pull request may close this issue.

1 participant