In this article, I will talk in detail about the implementation of the client API in TypeScript for working with both third-party APIs and my own. ...
For further actions, you may consider blocking this person and/or reporting abuse
This is pretty good, and I think you're on the right track, but it could be improved in a few ways.
You don't need to create so many instances. You're in JS which is single threaded. Your code is mostly stateless.
Use
unknown
instead ofany
. It saves mistakes later, and communicates your intent better to the caller.Abstract more. The caller of your code should know nothing of HTTP. You stated that a goal was to avoid change if your API changes. That's a good goal.
Thanks
Curious about the abstraction part? I may be missing it but how does the caller know anything of the HTTP?
Do you have a video of this? As a newbie i hardly able to catch that.
This ia a bit over engineered, isn't it!? It's easier and cleaner to use native es modules over classes. Then, there's no need to have a createClient in all methods, just important the axios instance. 😉
It's an irregular approach :)
Irregular!? Are you sure!? 🙃
I mean my approach that I've shown in this article
Great article.
Thank you
I'd recommend not to write an API client but instead generate it. I wrote this github.com/nfroidure/openapi-ts-sd... for generating a SDK from OpenAPI, it is still highly customizable but It avoids repeating myself.
I agree with other comments to avoid classes too.
This is really a good alternative
Great Article Sir
Thanks a lot