3 ms·
I'm not sure fetch is a good server-side API. The typical fetch-based code snippet `fetch(API_URL).then(r => r.json())` has no response body size limit and can
by cyco130 8mo ago
I'm not sure fetch is a good server-side API. The typical fetch-based code snippet `fetch(API_URL).then(r => r.json())` has no response body size limit and can potentially bring down a server due to memory exhaustion if the endpoint at API_URL malfunctions for some reason. Fine in the browser but to me it should be a no-no on the server.
- augusto-moura 8mo agoHm, I don't think axios would do much better here. `fetch` is the official replacement for axios. If both are flawed that's another topic
- nailer 7mo ago> `fetch` is the official replacement for axios. No. Axios is still maintained. They have not deprecated the project in favor of fetch.
- augusto-moura 7mo agoI'm not saying that axios is unmaintained, I'm saying that if you want something like axios from the standard lib, fetch is the closest thing you get to official
- nailer 7mo agoSure but Axios determine what the official replacement for Axios is.
- kube-system 7mo agoIt's not deprecated, it's obsoleted.
- sieabahlpark 7mo ago[dead]
- cyco130 7mo agoAxios has maxContentLength and maxBodyLength options. I would probably go with undici nowadays though (it also has maxResponseSize).
- lelanthran 7mo ago> I'm not sure fetch is a good server-side API. The typical fetch-based code snippet `fetch(API_URL).then(r => r.json())` has no response body size limit and can potentially bring down a server due to memory exhaustion if the endpoint at API_URL malfunctions for some reason. Fine in the browser but to me it should be a no-no on the server. Nor is fetch a good client-side API either; you want progress indicators, on both upload and download. Fetch is a poor API all-round.
- WorldMaker 7mo agoYou can pass to `fetch` an `AbortSignal` like `AbortSignal.timeout(5000)` as a simple and easy guard. If you also want to guard on size, iterating the `response.body` stream with for/await/of and adding a counter that can `abort()` a manual `AbortSignal` is relatively straightforward, though sounds complicated. You can even do that as a custom `ReadableStream` implementation so that you can wrap it back into `Response` and still use the `response.json()` shortcut. I'm surprised I'm not seeing a standard implementation of that, but it also looks straightforward from MDN documentation [1]. [1] https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams#reading_the_stream https://developer.mozilla.org/en-US/docs/Web/API/Streams_API...
- vakrdotme 7mo agoBrowser fetch can lean on the fact that the runtime environment has hard limits per tab and the user will just close the tab if things get weird. on the server you're right