3.3.4 • Published 6 months ago

fetch-media v3.3.4

Weekly downloads
96
License
MIT
Repository
-
Last release
6 months ago

fetch-media

Utility function that uses fetch to fetch a media-enabled resource

Does not work flawlessly with Node 18+ fetch because their Response class is implemented differently; may or may not work well with libraries that change the global fetch.

Installation

yarn add fetch-media

If you're using react-native, this will use the unbundled source TypeScript. As such, the normally rolled-up dependency @ungap/url-search-params isn't available.

You must install this dependency.

yarn add @ungap/url-search-params

Usage

import { fetchMedia } from 'fetch-media';

/**
 * Fetches media from a URL
 *
 * - Automatically encodes the request body if the contentType is a JSON type
 * - Automatically decodes the response body
 *    - as parsed JSON if it's JSON
 *    - as string if it's text
 *    - as ArrayBuffer or Blob if it's binary
 *    - as FormData if it's multipart/form-data
 *    - as UrlSearchParams if it has a body of url encoded form data
 * - Automatically parses errors, problems, structured errors, etc.
 *
 * @see MediaOptions
 *
 * @param url the fully qualified url to fetch from
 * @param param1 the {MediaOptions}
 * @returns A fetch promise
 */

fetchMedia('https://example.org', {
  headers: { accept: 'text/html' },
  method: 'GET',
}).then((result) => {
  /* html body as string */
});

You can use fetchMediaWrapped to get the full response (so you can read out headers)

3.3.1

6 months ago

3.3.0

6 months ago

3.3.4

6 months ago

3.3.2

6 months ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.1.6

4 years ago

2.1.5

4 years ago

2.1.2

4 years ago

2.1.4

4 years ago

2.1.3

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

2.0.0-rc6

4 years ago

2.0.0-rc5

4 years ago

2.0.0-rc4

4 years ago

2.0.0-rc3

4 years ago

2.0.0-rc2

4 years ago

2.0.0-rc1

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago