5 ms·
Oh ok, I guess I could also do the following then class JsonBody extends Blob { constructor (obj) { super([JSON.stringify(obj)], { type : 'ap
by janpot 5y ago
Oh ok, I guess I could also do the following then
class JsonBody extends Blob {
constructor (obj) {
super([JSON.stringify(obj)], { type : 'application/json' })
}
}
fetch(url, { method: 'POST', body: new JsonBody({ hello: 'world' }) })
That's quite handy
- jaffathecake 5y agofwiw, I don't think this should be a class. It could just be: const createJSONBlob = (obj) => new Blob([JSON.stringify(obj)], { type : 'application/json' });
- janpot 5y agoSure, makes sense in this case, without any other extra functionality in the class. But there could be more functionality needed. It feels highly subjective to me.
- jetbooster 5y agodelete this before copilot finds it and suggests it!