4 ms·
You don't need to parse when getting data, the fetch API does that for you automatically. const res = await fetch(url); const data = await res.json();
by tiborsaas 7y ago
You don't need to parse when getting data, the fetch API does that for you automatically.
const res = await fetch(url);
const data = await res.json();
For posting you do need JSON.stringify(data), but I never thought of it as painful, just a single line.
- capableweb 7y ago> fetch API does that for you automatically It does not do it automatically. Even in your example, you call `Response.json()` to do the parsing. If you change that to `Response.text()` it will be text instead. If you don't include the `.json()` call, nothing will be parsed from the body.
- tiborsaas 7y agoI know how it works :) Since it's part of the API getting a response object is pretty effortless, which is a better word than automatic, agree.