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

feat: add KY data provider to simple-rest package #6544

Closed

Conversation

OmkarBansod02
Copy link
Contributor

@OmkarBansod02 OmkarBansod02 commented Dec 1, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

The @refinedev/simple-rest package currently includes only an Axios-based data provider. Users do not have the option to use KY for handling HTTP requests.

What is the new behavior?

The package now includes a KY-based data provider, providing users with an alternative lightweight HTTP client. The KY provider mirrors the Axios implementation's structure, ensuring consistency, type safety, and robust error handling.

fixes #6381

Notes for reviewers

i’ve added the KY data provider to the @refinedev/simple-rest package, following the same structure as the Axios provider. The key difference is KY’s simplicity and built-in query handling, which makes the implementation lighter and more efficient for
certain use cases. You can find more about KY here: KY Documentation.

Here is comparison :

Axios Example :

Screenshot 2024-12-01 171936

KY Example:

Screenshot 2024-12-01 172327

KY is a lightweight and simpler alternative to Axios. It uses searchParams for query parameters and simplifies response handling with .json().

  • I haven’t included tests yet because i wanted to get an initial review to ensure the implementation is solid. If the code looks strong, I will proceed to add test cases in a follow-up.

  • i need your input on whether this change should be categorized as minor or major for the changesets.

Looking forward to your feedback and suggestions for improvement!

Thanks!

@OmkarBansod02 OmkarBansod02 requested a review from a team as a code owner December 1, 2024 12:01
Copy link

changeset-bot bot commented Dec 1, 2024

⚠️ No Changeset found

Latest commit: f945a04

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Member

@BatuhanW BatuhanW left a comment

Choose a reason for hiding this comment

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

Hey @OmkarBansod02 thanks for the PR!

Added some minor comments, generally it looks good. We'll know better when the tests are added. Make sure you use nock library to record new requests and create tests based on them.

Looking forward to your updates 🚀

"nock": "^13.4.0",
"query-string": "^7.1.1",
Copy link
Member

Choose a reason for hiding this comment

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

Let's use qs package because it supports encoding query params with nested structures.

@@ -48,9 +68,12 @@
"@refinedev/cli": "^2.16.33",
"@refinedev/core": "^4.52.0",
"@types/jest": "^29.2.4",
"axios": "^1.6.2",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"axios": "^1.6.2",

We don't need this, it should be in dependencies already.

Comment on lines +22 to +44
export const kyInstance = ky.create({
hooks: {
afterResponse: [
async (_request, _options, response) => handleErrorResponse(response),
],
},
});

export const createKyInstance = (
baseUrl?: string,
options?: KyOptions,
): KyInstance => {
return ky.create({
prefixUrl: baseUrl,
...options,
hooks: {
afterResponse: [
async (_request, _options, response) => handleErrorResponse(response),
],
...options?.hooks,
},
});
};
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kyInstance is a default instance of ky with a pre-configured setup (e.g., error handling hooks). kyInstance is sufficient for refinedev usecase.

I added createKyInstance to allow more flexibility, like using multiple APIs or customizing hooks if needed. If this flexibility isn’t useful for refine.dev right now, we can remove it to keep things simpler.

Copy link
Member

Choose a reason for hiding this comment

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

Where do we use createKyInstance?

@BatuhanW
Copy link
Member

BatuhanW commented Dec 5, 2024

Hey @OmkarBansod02 thanks for the PR. I'll need to close it and update the issue with more details, since it wasn't explained well. I'll discuss with core team to decide for necessary changes.

@BatuhanW BatuhanW closed this Dec 5, 2024
@OmkarBansod02
Copy link
Contributor Author

Hey @OmkarBansod02 thanks for the PR. I'll need to close it and update the issue with more details, since it wasn't explained well. I'll discuss with core team to decide for necessary changes.

No problem. If core team approve it create an issue with more details, i would love to work on it.🚀

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.

[FEAT] Add a dataprovider using KY
2 participants