Skip to content

API Client

The Client class provides an easy way to interact with the REST-API to manage domain resources.

Configuration

To configure the API Client, the baseURL parameter for the driver config of the constructor should be set.

typescript
import { Client } from '@authup/core-http-kit';

const client = new Client({
    baseURL: 'http://127.0.0.1:3010/'
});

Domains

The Client exposes the following sub-API clients as instance properties:

PropertyAPI ClassDescription
tokenOAuth2TokenAPIOAuth2 token operations
authorizeOAuth2AuthorizeAPIOAuth2 authorization
clientClientAPIClient management
clientPermissionClientPermissionAPIClient-permission associations
clientRoleClientRoleAPIClient-role associations
clientScopeClientScopeAPIClient-scope associations
identityProviderIdentityProviderAPIIdentity provider management
identityProviderRoleMappingIdentityProviderRoleMappingAPIIdentity provider role mappings
policyPolicyAPIPolicy management
permissionPermissionAPIPermission management
realmRealmAPIRealm management
robotRobotAPIRobot management
robotPermissionRobotPermissionAPIRobot-permission associations
robotRoleRobotRoleAPIRobot-role associations
roleRoleAPIRole management
roleAttributeRoleAttributeAPIRole attribute management
rolePermissionRolePermissionAPIRole-permission associations
scopeScopeAPIScope management
userUserAPIUser management
userInfoOAuth2UserInfoAPIOAuth2 user info
userAttributeUserAttributeAPIUser attribute management
userPermissionUserPermissionAPIUser-permission associations
userRoleUserRoleAPIUser-role associations

Each property is named after the domain in camelCase.

For example:

typescript
import { Client } from '@authup/core-http-kit';

const client = new Client(/* ... */);

const response = await client.realm.create({
    name: 'Test Realm'
});

console.log(response);
// { id: 'xxx', name: 'Test Realm', ... }

Request & Responses

Nearly each domain API (e.g. UserAPI) exposes the same CRUD methods with few exceptions. The most common methods are:

  • getOne
  • getMany
  • create
  • update
  • delete

The response of a resource collection request always returns meta information about how many items (total) are available for the given predicate(s) and which part of the data set is returned (limit & offset).

typescript
import { Client } from '@authup/core-http-kit';

const client = new Client({
    /* ... */
});

const response = await client.role.getMany({
    page: {
        limit: 10,
        offset: 0
    }
});

console.log(response);
// {
//      meta: {total: 1, limit: 10, offset: 0},
//      data: [{id: 'xxx', name: 'admin', description: null}],
// }

The response of a single resource request always returns the resource object without meta information.

typescript
import { Client } from '@authup/core-http-kit';

const client = new Client({
    /* ... */
});

const response = await client.role.getOne('xxxx-xxxx-xxxx-xxxx');

console.log(response);
// {
//     id: 'xxx', name: 'admin', description: null
// }