- From: jods <notifications@github.com>
- Date: Wed, 06 Jun 2018 06:50:09 -0700
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/104/395075323@github.com>
@domenic your answer is dismissing this issue purely on implementation details. The idea that API `.json(reviver)` should exist seems appealing to me. How it is implemented is up to browsers. At "worse", a browser could have a C++ path with no argument and fallback to `.body().then(json => JSON.parse(json, reviver))` when there's an argument. The point is: - `Body.json()` is not consistent with `JSON.parse(text[, reviver])`. It's the same core function but it doesn't have the same API, which is surprising (in a bad way). - JSON being what it is, revivers are quite useful. E.g. to replace strings with `Date`, since in 2018 automatically serializing dates is still an unsolved problem; or to create typed objects based on `$type`. The work-around `fetch("api/hello").then(r => r.body()).then(text => JSON.parse(text, reviver))` is not very pretty, there's no reason that we shouldn't be able to do `fetch("api/hello").then(r => r.json(reviver))` Plus, _some_ browsers might be able to offer more optimized implementations? An optimized C++ API is not as useful if it's unusable (`.body()` instead) or if you have to post-process your object graph after it's been deserialized (which moots the performance win). -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/fetch/issues/104#issuecomment-395075323
Received on Wednesday, 6 June 2018 13:50:34 UTC