Skip to content
This repository has been archived by the owner on Dec 2, 2019. It is now read-only.

document usage with fetch, ky(sindre), websockets & sockette(lukeed) #6

Open
2 tasks
davalapar opened this issue Mar 5, 2019 · 0 comments
Open
2 tasks

Comments

@davalapar
Copy link
Owner

davalapar commented Mar 5, 2019

Overview

  • Document usage in README
  • Provide simple wrapper functions that automatically encodes parameters, and decodes responses
const { encode, decode } = //...
const response = await fetch('https://example.com', {
  method: 'POST',
  body: JSON.stringify({foo: true}),
  headers: { 'content-type': 'application/octet-stream' }
});
if (!response.ok) {
  throw new HTTPError('Fetch error:', response.statusText);
}
const parsed = decode(await response.arrayBuffer());
console.log(parsed);
//=> `{ asd: '123'}`
const headers = { 'content-type': 'application/octet-stream' };
const parsed = decode(await ky.post('https://example.com', {
  headers,
  body: encode({ some: 'data' }),
}).arrayBuffer());

References

@davalapar davalapar changed the title document usage with ky document usage with fetch & ky Mar 5, 2019
@davalapar davalapar changed the title document usage with fetch & ky document usage with fetch, ky(sindre), websockets & sockette(lukeed) Mar 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant