StbX / directus-sdk-javascript

Directus SDK for JavaScript (Node and Browser)

Home Page:https://getdirectus.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

directus-sdk-javascript

Directus SDK for JavaScript (Node and Browser)

Directus Logo

Installation

Install the package using npm or Yarn:
npm install directus-sdk-javascript --production or yarn add directus-sdk-javascript

Or download the repo and include /dist/remote.js into your document:
<script src="/dist/remote.js"></script>

Or use a service that distributes npm packages like unpkg:
<script src="https://unpkg.com/directus-sdk-javascript/dist/remote.js"></script>

Usage

Create a new client passing it the options needed to create a connection:

// Only in Node / non-bundled version:
const RemoteInstance = require('directus-sdk-javascript/remote');

// Or (es6+):
import { RemoteInstance } from 'directus-sdk-javascript';

const client = new RemoteInstance({
  url: 'http://instance.directus.io/api/1.1/',
  accessToken: [user-token] // optional, can be used without on public routes
});

The client provides methods for each API endpoint. Every endpoint returns a promise which resolves the APIs JSON on success and rejects on an error:

client.getItems('projects')
  .then(res => console.log(res))
  .catch(err => console.log(err));

Since the SDK uses promises, you can also use it with async/await:

const projects = await client.getItems('projects');

Check the official API docs for a complete overview of all endpoints and available methods

About

Directus SDK for JavaScript (Node and Browser)

https://getdirectus.com/

License:GNU General Public License v3.0


Languages

Language:JavaScript 100.0%