3.37.0 • Published 7 days ago

@studyportals/domain-client v3.37.0

Weekly downloads
19
License
BSD-3-Clause
Repository
-
Last release
7 days ago

Domain Client

A lightweight client for fetching data from the Domain API and returning it as strongly typed classes defined by the Domain API.

Installation

npm install @studyportals/domain-client --save

Default usage

Instantiate your client class (ProgrammeCard client as example) with all parameters:

const client = new ProgrammeCardClient(
    domainApiUrl, // The url to the Domain API endpoint
    apiKey, // The API key provided by PLOP for your implementation
    probabilitySeed // Number between 1 and 100 (inclusive)
);

Fetch your model using the fetch() method with the requested ID (in this example programme ID):

const card: IProgrammeCard = await client.fetch(5);

Or get multiple using fetchMultiple() with the requested IDs (in this example programme IDs):

const cards: IProgrammeCard[] = await client.fetchMultiple([5, 9, 13]);

Some functions are accompanied by a canShow function that indicates its availability. If the value is not set the function will throw a PropertyNotAvailableException:

const card: IProgrammeCard = await client.fetch(5);

// Might throw PropertyNotAvailableException
const cover: ICover = card.getCover();

// Safe behaviour
if (card.canShowCover()) {
    const cover: ICover = card.getCover();
}

Separated usage

In some cases you might want to separate the fetching of the information from the usage of that information; for instance getting the information in your back-end service and passing it to the front-end application for usage.

First instantiate your client class with all parameters:

const client = new ProgrammeCardClient(
    domainApiUrl, // The url to the Domain API endpoint
    apiKey, // The API key provided by PLOP for your implementation
    probabilitySeed // Number between 1 and 100 (inclusive)
);

To do this you can use the fetchDescription() method instead and encode it as JSON:

const card: IModelDescription = await client.fetchDescription(5);
const jsonData: string = JSON.stringify(card);

Or use the fetchMultipleDescriptions() function to fetch multiple descriptions:

const cards: IModelDescription[] = await client.fetchMultipleDescriptions([5, 9, 13]);
const jsonData: string = JSON.stringify(cards);

When you're ready to use the information in the models you can use the existing client or instantiate a new one without parameters:

const client = new ProgrammeCardClient();

After which you can use the fromDescription() and fromDescriptions() functions to retrieve your models:

const descriptions: IModelDescription[] = JSON.parse(jsonData);
const card: IProgrammeCard = client.fromDescription(descriptions[0]);
const cards: IProgrammeCard[] = client.fromDescriptions(descriptions);

Note that creating a client without providing the required parameters will result in all network functionalities of the client being unavailable. In this case the following functions will throw a ClientException:

await client.fetch(1);
await client.fetchMultiple([5, 9, 13]);
await client.fetchDescription(1);
await client.fetchMultipleDescriptions([5, 9, 13]);
3.37.0

7 days ago

3.36.1-beta.0

8 days ago

3.36.0

14 days ago

3.35.0

15 days ago

3.34.0

16 days ago

3.33.0

2 months ago

3.32.0-1

2 months ago

3.32.0-2

2 months ago

3.31.0

2 months ago

3.30.0

3 months ago

3.29.2-beta.2

3 months ago

3.29.1

4 months ago

3.29.0

4 months ago

3.28.0

4 months ago

3.27.0

4 months ago

3.27.0-0

4 months ago

3.27.0-beta.0

4 months ago

3.26.0

6 months ago

3.21.1-beta.0

9 months ago

3.20.0

9 months ago

3.24.0

8 months ago

3.17.0

10 months ago

3.17.1

10 months ago

3.24.1

8 months ago

3.24.1-beta.0

8 months ago

3.21.0

9 months ago

3.18.0

10 months ago

3.19.1-beta.0

9 months ago

3.25.0

7 months ago

3.22.0

9 months ago

3.24.0-beta.0

8 months ago

3.19.0

10 months ago

3.23.0

9 months ago

3.26.0-beta.0

6 months ago

3.25.0-beta.0

7 months ago

3.16.1-beta.3

11 months ago

3.16.1-beta.2

11 months ago

3.16.1-beta.1

11 months ago

3.16.1-beta.0

11 months ago

3.15.0

12 months ago

3.16.0-0

12 months ago

3.16.0

11 months ago

3.14.0-1

12 months ago

3.14.0-0

12 months ago

3.14.0-schcard.1

12 months ago

3.14.0-schcard.0

12 months ago

3.14.0

12 months ago

3.12.1

1 year ago

3.12.0

1 year ago

3.13.0-1

1 year ago

3.13.0-0

1 year ago

3.13.0

1 year ago

3.13.0-2

1 year ago

3.11.0

1 year ago

3.12.0-0

1 year ago

3.12.0-1

1 year ago

3.9.1-0

1 year ago

3.9.1

1 year ago

3.9.0

1 year ago

3.10.1

1 year ago

3.10.0

1 year ago

3.10.0-2

1 year ago

3.10.0-1

1 year ago

3.10.0-beta.0

1 year ago

3.8.0

1 year ago

3.9.0-0

1 year ago

3.8.0-0

1 year ago

3.10.0-0

1 year ago

3.6.1-beta.2

1 year ago

3.6.1-beta.1

1 year ago

3.6.2

1 year ago

3.6.1

1 year ago

3.6.2-beta.3

1 year ago

3.6.2-beta.0

1 year ago

3.6.2-beta.1

1 year ago

3.7.0-beta.2

1 year ago

3.7.0-beta.1

1 year ago

3.7.0-beta.0

1 year ago

3.7.0

1 year ago

3.6.0

2 years ago

3.7.0-0

2 years ago

3.6.0-0

2 years ago

3.6.0-1

2 years ago

3.6.0-2

2 years ago

3.5.2

3 years ago

3.5.2-beta.0

3 years ago

3.5.2-beta.1

3 years ago

3.5.1

3 years ago

3.5.1-beta.0

3 years ago

3.5.0

3 years ago

3.5.0-beta.2

3 years ago

3.4.0

3 years ago

3.5.0-beta.1

3 years ago

3.3.0-beta.4

3 years ago

3.3.0-beta.3

3 years ago

3.3.0

3 years ago

3.3.0-beta.1

3 years ago

3.3.0-beta.0

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.2-1

3 years ago

2.0.2-0

3 years ago

2.0.1

3 years ago

1.0.0

3 years ago

1.0.0-beta.17

3 years ago

1.0.0-beta.2

3 years ago

1.0.0-beta.3

3 years ago

1.0.0-beta.4

3 years ago

1.0.0-beta.5

3 years ago

1.0.0-beta.11

3 years ago

1.0.0-beta.12

3 years ago

1.0.0-beta.10

3 years ago

1.0.0-beta.6

3 years ago

1.0.0-beta.7

3 years ago

1.0.0-beta.8

3 years ago

1.0.0-beta.15

3 years ago

1.0.0-beta.16

3 years ago

1.0.0-beta.13

3 years ago

1.0.0-beta.14

3 years ago

1.0.0-beta.1

3 years ago

1.0.0-beta.0

3 years ago

1.0.0-alpha.2

3 years ago

1.0.0-alpha.1

3 years ago

1.0.0-alpha.0

3 years ago