ky: Like fetch() but less bad

preview_player
Показать описание
Fetch revolutionized web development by...existing. I think we deserve better though. Is `ky` the better we've been looking for?

S/O Ph4se0n3 for the awesome edit 🙏
Рекомендации по теме
Комментарии
Автор

Wait, you guys don't use axios anymore 😂

Niksorus
Автор

It feels more like iteration on Axios than it is on fetch. I see Ky and immediately think “oh it’s just slightly different axios”, at least in terms of using it

ggnorton
Автор

Fetch has its quirks for sure! Ever thought about using HasData to scrape responses while using ky?

oliverwiggins
Автор

I really dont see why should i go all the way from axios just to have another library instead. What's wrong wth axios?

sagiyoav
Автор

this is bs, just make an util function that includes all the default headers and you have it

fra
Автор

XHR is for beta devs. real devs reload their entire page to fetch new data from the server.

itskishank
Автор

Axios has fetch adapter now, why change Axios to anything else ?

thedoctorde
Автор

I've been coding for 28 years and I would absolutely use this. Call me a junior dev, idc. I know it wouldn't work in enterprise, I know it's not as easy to outsource, idc. I simply wouldn't work for a company like the one you do in the 1st place. As long as we're making up dumb competitions, using abstractions instead of redundantly typing out the same boilerplate still makes me better than you because I can do more than you in less time and spend the limited time I have on this earth innovating on novel features that are actually interesting instead of maximizing shareholder value. It's like excavators just dropped and you're not gonna use one because experienced hole diggers know they aren't compatible with the guidelines all your coworkers that still use plastic spoons use. Weird flex but ok.
I disagree that AI makes fetch the better option. It can easily learn ky from in context learning, and we're not far off it just reading the entire codebase anyway. Simple succinct code only makes it less likely to hallucinate and easier for it or you to debug. It could even trim functions in the library that aren't needed and add them back in when they are.

steve_jabz
Автор

I just use axios. Why use something else? Does fetch support interceptors?

MrXperx
Автор

To quote ThePrimeTime - "skill issue".

jouebien
Автор

are you telling me you don't have a wrapper over fetch in your production apps which does all the magic of defaults, error handling, logging, and TS related shit and auth token rotations ?

hannad
Автор

I don't understand the point of adding a dependency for something that would take you like 30 minutes and 20 lines of code to reproduce.

JoRyGu
Автор

The .json<Foo>() thing, is convenient but typescript will assume that the thing received matches that type going forward. It might very well be a lie.

nefthy
Автор

Bruh, what do you mean used, We still use axios 😮

joe-robin
Автор

I really think the example you used between ky vs fetch, in the queryFn, was really simple and in that case makes really no sense to use a wrapper lib. It would be the same case using axios instead of fetch. The reason you would want to use ky is if you want to use it's built-in interceptors (same thing using axios).

For example: what if in every request you need to check if your token is valid or something like that. If you only use fetch now you need to build a wrapper for it and what if you also need to log some errors whenever there is an http error, another wrapper you need to build. With ky you can use it's middleware hooks, which are basically interceptors, that makes you do all these things in the same config.

With ky, you don't need to build multiple wrappers and also have the possibility to use the onDownloadProgress which fetch doesn't have (another wrapper basically).

TLDR: If you need a bunch of interceptors and you want to use the fetch api use ky, if not fetch is enough.

gomesiano
Автор

I thought you just took my 13 minutes for nothing. I just needed some patience, beautifully explained! React query in react is a perfect example. It's not about ky vs fetch. Indeed, It's about the analysing associated costs and benefits whenever these kinds of decisions are to be made.

abhishekprajapati
Автор

Been using react query for months. It's a life-saver if you're building anything mildly complex.

filobonda
Автор

I see positive here because it's not about react, so can be used in vanilla JS.

XCanG
Автор

bruh, ofetch solved fetch problems a long time ago

ortson
Автор

You know, you can kinda learn anything as basic as this 'ky' in 15 minutes or less. I literally never seen it before and it sounds familiar.
So I think there is a larger problem with people self declaring themselves "senior detection machines" or whatever that at the same time are downgrading the world into their own worldviews about how problems should be solved (and that everything outside of that field is "unexperienced"). Put 5 of them in a room and every single one of them will be saying the other is not a real senior very fast.
But I get the point, I'm just being a bit harsh.

diadetediotedio