https://github.com/prezly/javascript-sdk
Javascript SDK to interact with Prezly API
https://github.com/prezly/javascript-sdk
api coverage prezly sdk
Last synced: 20 days ago
JSON representation
Javascript SDK to interact with Prezly API
- Host: GitHub
- URL: https://github.com/prezly/javascript-sdk
- Owner: prezly
- License: mit
- Created: 2019-11-19T12:41:37.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-04-11T07:49:25.000Z (21 days ago)
- Last Synced: 2025-04-11T22:52:20.647Z (20 days ago)
- Topics: api, coverage, prezly, sdk
- Language: TypeScript
- Homepage: https://www.prezly.com/
- Size: 1.81 MB
- Stars: 5
- Watchers: 8
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Prezly JavaScript SDK
### Getting started
```sh
npm install --save @prezly/sdk
# or yarn
yarn add @prezly/sdk
```### Using the code
Using ES Modules:
```js
import { createPrezlyClient } from '@prezly/sdk';const prezlyClient = createPrezlyClient({
accessToken: 'your-access-token',
});
```Or Using CommonJS:
```js
const { createPrezlyClient } = require('@prezly/sdk').default;const prezlyClient = createPrezlyClient({
accessToken: 'your-access-token',
});
```## Requirements
### API token
At this moment, the UI does not support issuing API tokens. Please contact support to issue one for you.
### [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) API support
`@prezly/sdk` is using `fetch` to create requests. We assume that the environment running the code supports it.
We understand that some of the environments, such as node.js or old browsers, do not support `fetch`. This can be resolved by including a polyfill.
#### Polyfilling in browsers using [`whatwg-fetch`](https://www.npmjs.com/package/whatwg-fetch)
```sh
npm install --save whatwg-fetch
# or yarn
yarn add whatwg-fetch
``````js
import 'whatwg-fetch';
// ...
import { createPrezlyClient } from '@prezly/sdk';
```We recommend referring to the [official `whatwg-fetch` module documentation](https://www.npmjs.com/package/whatwg-fetch) for more information.
#### Polyfilling in browsers using [`node-fetch`](https://www.npmjs.com/package/node-fetch)
```sh
npm install --save node-fetch
# or yarn
yarn add node-fetch
``````js
global.fetch = require('node-fetch');
// ...
const { createPrezlyClient } = require('@prezly/sdk');
```We recommend referring to the [official `node-fetch` module documentation](https://www.npmjs.com/package/node-fetch) for more information.
#### Platform-agnostic polyfill using [`cross-fetch`](https://www.npmjs.com/package/cross-fetch)
```sh
npm install --save cross-fetch
# or yarn
yarn add cross-fetch
```Using ES Modules:
```js
import 'cross-fetch/polyfill';
// ...
import { createPrezlyClient } from '@prezly/sdk';
```Or Using CommonJS:
```js
require('cross-fetch/polyfill');
// ...
const { createPrezlyClient } = require('@prezly/sdk');
```We recommend referring to the [official `cross-fetch` module documentation](https://www.npmjs.com/package/cross-fetch) for more information.
#### Custom `fetch` implementation
Additionally, you can initialize the API client with your own implementation of `fetch`:
```js
import { createPrezlyClient } = from '@prezly/sdk';const prezlyClient = createPrezlyClient({
accessToken: 'your-access-token',
fetch: customFetch,
});
```