d2l-content-service-api-client
v7.10.0
Published
Content Service API client
Downloads
5
Readme
d2l-content-service-api-client
Content Service API clients with support for a configurable HTTP client for usage in Node and the browser.
Supported HTTP Clients
- d2l-content-service-browser-http-client - Browser-based HTTP client
- d2l-content-service-node-http-client - Node-based HTTP client
Usage (ContentServiceApiClient)
Node
const ContentServiceNodeHttpClient = require('d2l-content-service-node-http-client');
const { ContentServiceApiClient } = require('d2l-content-service-api-client');
const httpClient = new ContentServiceNodeHttpClient({ ... });
const client = new ContentServiceApiClient({
httpClient,
tenantId: '00000000-0000-0000-0000-000000000000',
contextType: 'topic',
contextId: '12345'
});
const result = await client.content.getItem({ id: 'foo' });
Browser
import ContentServiceBrowserHttpClient from 'd2l-content-service-browser-http-client';
import { ContentServiceApiClient } from 'd2l-content-service-api-client';
const httpClient = new ContentServiceBrowserHttpClient({ ... });
const client = new ContentServiceApiClient({
httpClient,
tenantId: '00000000-0000-0000-0000-000000000000',
contextType: 'topic',
contextId: '12345'
});
const result = await client.content.getItem({ id: 'foo' });
Parameters
httpClient
: HTTP clienttenantId
: LMS tenant ID. Used in tenant-scoped API calls.contextType
(optional):topic
orplacement
. This option describes the LE context in which the API calls are being made. This is only valid when using LE user tokens, and provides access to Content Service objects based on LE resources, such as topics or ISF/QuickLinks/Attachments placements. It provides users with access to certain Content Service objects based on their LE permissions/enrolments.contextId
: The ID of thecontextType
. For instance, ifcontextType
istopic
, this would be the topic ID
Usage (BrightspaceApiClient)
Node
const ContentServiceNodeHttpClient = require('d2l-content-service-node-http-client');
const { BrightspaceApiClient } = require('d2l-content-service-api-client');
const httpClient = new ContentServiceNodeHttpClient({ ... });
const client = new BrightspaceApiClient({ httpClient });
const result = await client.getContentServiceEndpoint();
Browser
import ContentServiceBrowserHttpClient from 'd2l-content-service-browser-http-client';
import { BrightspaceApiClient } from 'd2l-content-service-api-client';
const httpClient = new ContentServiceBrowserHttpClient({ ... });
const client = new ContentServiceApiClient({ httpClient });
const result = await client.getContentServiceEndpoint();
Parameters
httpClient
: HTTP client
Usage (CaptureApiClient)
Node
const ContentServiceNodeHttpClient = require('d2l-content-service-node-http-client');
const { CaptureApiClient } = require('d2l-content-service-api-client');
const httpClient = new ContentServiceNodeHttpClient({ ... });
const client = new CaptureApiClient({ httpClient });
const result = await client.getEvent({ id, orgUnitId });
Browser
import ContentServiceBrowserHttpClient from 'd2l-content-service-browser-http-client';
import { CaptureApiClient } from 'd2l-content-service-api-client';
const httpClient = new ContentServiceBrowserHttpClient({ ... });
const client = new CaptureApiClient({ httpClient });
const result = await client.getEvent({ id, orgUnitId });
Parameters
httpClient
: HTTP client
Supported APIs
View the source code to see supported API methods. If something is missing, add it!
Creating a custom HTTP Client
You can make your own HTTP client by extending AbstractHttpClient
(a named export of d2l-content-service-api-client
) and implementing the required functions. See the existing HTTP client implementations for examples.