orval icon indicating copy to clipboard operation
orval copied to clipboard

feat: add new client `fetch`

Open soartec-lab opened this issue 1 year ago • 8 comments

Status

READY

Description

Fix #1387

I added a new fetchclient. Becouse, since the fetch API is mature, it has the advantage of reducing the bundle size of the application compared to using Axios, and I feel that this is sufficient in some cases. Furthermore, we think it can be used to select an HTTP client with tanstack query or swr, or when calling an API from a server-side framework.

In this PR, i implemented a client using the minimal fetch API. For example, customization by specifying mutator is not yet supported. However, I still think it is practical enough and would like to submmit it on first. I'll also submit a sample application in a subsequent PR.

Ref: https://developer.mozilla.org/en-US/docs/Web/API/fetch

Related PRs

none

Todos

  • [x] Tests
  • [x] Documentation
  • [x] Changelog Entry (unreleased)

Steps to Test or Reproduce

I added a test case, so it should pass.

soartec-lab avatar May 03 '24 05:05 soartec-lab

the params are passed to the body. Is it intended?

anymaniax avatar May 13 '24 08:05 anymaniax

thanks. I'll check later 👍

soartec-lab avatar May 13 '24 10:05 soartec-lab

Also code conflict might want to merge update.

melloware avatar May 13 '24 11:05 melloware

@soartec-lab it's what I use in my project if you need https://gist.github.com/anymaniax/44c1331a5643081a82da070e45f405f0

anymaniax avatar May 13 '24 12:05 anymaniax

@anymaniax wonderful. Thank you for sharing 🙌 I will use this as a reference when adding a custom instance in a future PR.

the params are passed to the body. Is it intended?

This is by design. Referring to this, I interpret that the request parameters are to be specified in the body.

https://developer.mozilla.org/en-US/docs/Web/API/fetch

soartec-lab avatar May 13 '24 13:05 soartec-lab

@soartec-lab If you pass the query params into the body it wont be a query params anymore or I am missing something?

anymaniax avatar May 13 '24 13:05 anymaniax

@anymaniax I see, the sample you shared with me adds query parameters to the URL. I will refer to it and consider it again.

soartec-lab avatar May 13 '24 13:05 soartec-lab

Hi, @anymaniax

I took your advice into consideration and changed the URL used by fetch to be obtained from a get URL function. This function combines path parameters and query parameters. And they only use the request body for body parameters.

Cloud you review again ?

soartec-lab avatar May 19 '24 03:05 soartec-lab

@anymaniax Thank you for the review. I have fixed all responses and commented.

I wanna add the fetch client incrementally and improve it little by little. First of all, I'm adding a minimal working package, so additional behaviors can be added in subsequent PRs. Detailed plans are also managed in this issue.

https://github.com/anymaniax/orval/issues/1387

soartec-lab avatar Jun 05 '24 00:06 soartec-lab

@melloware

Even if i merge this, I don't wanna close #1387, so I deleted fix #1387 in description, is there any problem?

soartec-lab avatar Jun 05 '24 00:06 soartec-lab

No problem! We can always reopen if it accidentally closes. I always prefer to have PR linked to ticket so we can reference later.

melloware avatar Jun 05 '24 00:06 melloware

Thanks !

soartec-lab avatar Jun 06 '24 00:06 soartec-lab