3.2.2 • Published 1 year ago

fetch-media v3.2.2

Weekly downloads
96
License
MIT
Repository
-
Last release
1 year ago

fetch-media

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

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.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.0

1 year ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.2

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

2.0.0-rc6

3 years ago

2.0.0-rc5

3 years ago

2.0.0-rc4

3 years ago

2.0.0-rc3

3 years ago

2.0.0-rc2

3 years ago

2.0.0-rc1

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago