Detalhes do pacote

sync-fetch

larsgw6.7mMIT0.6.0-2

Synchronous version of the Fetch API

fetch, sync

readme (leia-me)

sync-fetch

Synchronous wrapper around the Fetch API. Uses node-fetch under the hood, and for some input-parsing code and test cases too.

npm

Install

npm install sync-fetch

In the browser, a browserify bundle can be loaded from CDNs like unpkg.com.

<script src="https://unpkg.com/sync-fetch"></script>
<script src="https://unpkg.com/sync-fetch@VERSION"></script>

Use

const fetch = require('sync-fetch')

const metadata = fetch('https://doi.org/10.7717/peerj-cs.214', {
  headers: {
    Accept: 'application/vnd.citationstyles.csl+json'
  }
}).json()
// arrayBuffer(), blob(), buffer(), json(), and text() supported

Limitations

Node.js

  • Does not support Stream or Blob as input body since they cannot be read or serialized synchronously
  • Does not support FormData as input body yet as it has no built-in method to be serialized
  • Does not support the non-spec agent option as its value cannot be serialized
  • Does not support non-standard textConverted() method on SyncResponse and SyncRequest

Browser

  • Does not support most options, since XMLHttpRequest is pretty limited. Supported are:
    • method
    • body
    • headers
    • credentials (but not omit)
    • (Non-spec) timeout
  • The non-standard buffer() and textConverted() methods are not supported
  • CORS limitations apply, of course (note they may be stricter for synchronous requests)

changelog (log de mudanças)

0.6.0-2 (2024-11-20)

Features

  • add support for SyncResponse#blob() in Node.js (6b1e85c)

0.6.0-1 (2024-11-20)

Bug Fixes

  • fix handling of duplicate headers (b3460ca)

0.6.0-0 (2024-11-19)

Code Refactoring

  • upgrade to node-fetch 3 (071930c)

BREAKING CHANGES

  • drop support for Node 14, 16; upgrade to node-fetch 3

0.5.2 (2023-06-11)

  • update package definition (7325c8a)

0.5.1 (2023-06-11)

Bug Fixes

  • browser: correctly send request body (77a5b8f)
  • browser: fix text responses (ce210ce)
  • browser: remove SyncResponse#buffer() (5d17fba)

0.5.0 (2023-06-11)

  • refactor!: replace Buffer with TextEncoder and Uint8Array (1615baa), closes #27

BREAKING CHANGES

  • Support for IE and Edge <18 dropped.

0.4.5 (2023-06-11)

Bug Fixes

  • browser: fix binary responses (479a418)

0.4.4 (2023-06-11)

Features

  • browser: fetch binary outside Worker scopes (02611fc), closes #36

0.4.3 (2023-06-11)

Bug Fixes

  • transfer binary POST bodies correctly (cf5f592), closes #37

0.4.2 (2022-09-24)

0.4.1 (2022-05-26)

Bug Fixes

  • browser: re-add non-spec timeout option (168a46c)

0.4.0 (2022-05-26)

Bug Fixes

  • browser: improve browser compatibility (c65b3aa)
  • chore!: raise minimal Node.js version to 14 (096e7a3)

BREAKING CHANGES

  • Use Node.js 14 or higher. sync-fetch 0.3.x will keep getting critical security fixes if possible, but keep in mind that Node.js 12 itself is EOL and will itself not receive any security updates.

0.3.1 (2021-10-09)

Bug Fixes

  • transfer binary data correctly (674c848)

0.3.0 (2020-11-02)

  • chore!: drop node 8 and add 14 (b8b3e6c)

BREAKING CHANGES

  • drop Node 8 support

0.2.1 (2020-11-02)

Bug Fixes

  • call .join on stdin chunks array using empty string separator (bd609ad)

0.2.0 (2020-06-27)

  • refactor!: change class names (2e6a9ea)

BREAKING CHANGES

  • Changes Response and Request class names

0.1.1 (2019-10-24)

Bug Fixes

0.1.0 (2019-08-29)

Bug Fixes

  • body: also inline constructor (fe75247)
  • body: clone as sync instance (dd0b3c2)
  • body: default to null body (e5bd3b2)
  • body: do not consume body on clone (52dd003)
  • body: fix cloning consuming the body (8582046)
  • body: handle multi-value headers (379f55b)
  • body: inline body for super call (4b749f0)
  • body: make body methods enumerable (b20d190)
  • body: make clone method enumerable (27fa776)
  • body: only use super.buffer() (7558e7d)
  • body: pass stream to original Body (aa8a491)
  • body: throw error on stream input (ede18b8)
  • body: throw error when body already used (e78484d)
  • request: count other bodies as string (ed729f5)
  • request: pass body as-is (d36eb2a)
  • request: properly include headers (84a1de5)
  • request: special handling for input body strings (62c7876)
  • request: support node-fetch-only props (a6e3d38)
  • response: fix response error type (99ef625)
  • response: include url (a82beea)
  • response: properly include headers (7afa710)
  • response: support all body types (f7de954)
  • response: support redirected prop (0d9714f)
  • response: throw body errors late (d1fcbc4)
  • support Node 8 (52c0129)

Features

  • body: catch async errors (390ddab)
  • browser: make working browser alternative (ef05ffc)
  • fetch: improve child process handling (fece0fa)
  • fetch: support Node URL object input (d753191)
  • initial implementation (6f1563e)

0.5.1 (2023-06-11)

Bug Fixes

  • browser: correctly send request body (77a5b8f)
  • browser: fix text responses (ce210ce)
  • browser: remove SyncResponse#buffer() (5d17fba)

0.5.0 (2023-06-11)

  • refactor!: replace Buffer with TextEncoder and Uint8Array (1615baa), closes #27

BREAKING CHANGES

  • Support for IE and Edge <18 dropped.

0.4.5 (2023-06-11)

Bug Fixes

  • browser: fix binary responses (479a418)

0.4.4 (2023-06-11)

Features

  • browser: fetch binary outside Worker scopes (02611fc), closes #36

0.4.3 (2023-06-11)

Bug Fixes

  • transfer binary POST bodies correctly (cf5f592), closes #37

0.4.2 (2022-09-24)

0.4.1 (2022-05-26)

Bug Fixes

  • browser: re-add non-spec timeout option (168a46c)

0.4.0 (2022-05-26)

Bug Fixes

  • browser: improve browser compatibility (c65b3aa)
  • chore!: raise minimal Node.js version to 14 (096e7a3)

BREAKING CHANGES

  • Use Node.js 14 or higher. sync-fetch 0.3.x will keep getting critical security fixes if possible, but keep in mind that Node.js 12 itself is EOL and will itself not receive any security updates.

0.3.1 (2021-10-09)

Bug Fixes

  • transfer binary data correctly (674c848)

0.3.0 (2020-11-02)

  • chore!: drop node 8 and add 14 (b8b3e6c)

BREAKING CHANGES

  • drop Node 8 support

0.2.1 (2020-11-02)

Bug Fixes

  • call .join on stdin chunks array using empty string separator (bd609ad)

0.2.0 (2020-06-27)

  • refactor!: change class names (2e6a9ea)

BREAKING CHANGES

  • Changes Response and Request class names

0.1.1 (2019-10-24)

Bug Fixes

0.1.0 (2019-08-29)