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

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

@davalapar

Description

@davalapar

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions