Skip to main content

Common API guide

Swagger UI for API access

How to authenticate in swagger ui, refer to authentication in swagger ui.

Common API request headers / query params

KEYLocationDesc
x-refreshHeader, QueryGet entity by id or throw HTTP 404 if not found

Common API response headers

HEADERDesc
x-error-codeIndicate more error detail in addition to HTTP status code, for example, incase of access token expires HTTP code is 401, and x-error-code is access-token-expired

Common entities management (CRUD)

Entity objects

// Single entity object
interface Entity {}

// Entity list object
interface EntityList<Entity> {
// Total entity count
totalCount?: number;

// In fast counting, totalCount value is limited, use this value to indicate if the actual totalCount is larger than return totalCount
hasMoreCount?: boolean;

// Current data offset in full data set
offset?: number;

// Current data limit
limit?: number;

// Is has next data with current offset and limit, use in paging
hasNext?: boolean;

// Actual entity data list
items?: Entity[];
}

Parameters objects

// Entity create payload
interface EntityCreateDto {
// Data depend on entity data
[key: string]: any;
}

// Entity update payload
interface EntityUpdateDto {
// Data depend on entity data
[key: string]: any;
}

// Entity query parameter
interface EntityQuery {
// Detail filter object
filter?: EntityFilter;

// Select return field, ex [ 'id', 'name' ]
selector?: string[];

// Ordering by fields 1 (ASC) or -1 (DESC), ex { id: 1, name: -1 }
sort?: Record<string, 1 | -1>;

// Include soft deleted data
withDeleted?: boolean;

// Include fast total count in the query, the value is limited for fast query, use with hasMoreCount to check if there is more values
withFastTotalCount?: boolean;

// Include real total count in the query, this can be expensive operation
withTotalCount?: boolean;

// Limit the number of entities return
limit?: number;

// Select entities begin from skip
skip?: number;
}

// Entity filter parameters
interface EntityFilter {
// Mix of condition query like mongo https://www.mongodb.com/docs/manual/tutorial/query-documents/
// Support: $and, $or, $not, $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $like, $nlike, $ilike, $notilike, $isnull, $notnull, $regex, $iregex,
// Note: not all of entity fields are queriable, only fields selected by API developers can be put as query fields
// What fields are selected also depend on each entity, please consults the entity document for more info
[key: string]: any;
}

export interface EntityDeleteResult {
// How many entities deleted
affected: number;

// Ids of entities
ids?: string[];

// Id of entity
id?: string;
}

Get one

VERDEndpointParametersResponseDesc
GET/api/{entities}/:idNoneEntityGet one entity by id, throw HTTP 404 if not found
POST/api/{entities}/get-oneEntityQueryArgsEntityGet one entity by using query object, throw HTTP 404 if not found

Get many

VERDEndpointParametersResponseDesc
GET/api/{entities}NoneEntity[]Get all entities, internal limit is 1000

Find one

VERDEndpointParametersResponseDesc
POST/api/{entities}/find-one/:idNoneEntity or nullFind one entity by id, return null if not found
POST/api/{entities}/find-oneEntityQueryEntity or nullFind one entity by using query object, return null if not found
POST/api/{entities}/find-one-byEntityFilterEntity or nullFind one entity by using filter object, return null if not found

Find many

VERDEndpointParametersResponseDesc
POST/api/find-manyEntityQueryEntity[]Find many entities by using query object
POST/api/find-many-byEntityFilterEntity[]Find many entities by using filter object
POST/api/find-many-by-ids{ ids: string[]}Entity[]Find many entities by using id list
POST/api/find-many/listEntityQueryEntityListFind many entities as list by using query object

Create one

VERDEndpointParametersResponseDesc
PUT/api/{entities}EntityCreateDtoEntityCreate one entity
POST/api/{entities}/create-oneEntityCreateDtoEntityCreate one entity

Create many

VERDEndpointParametersResponseDesc
POST/api/{entities}/create-many{ items: EntityCreateDto[] }Entity[]Get all entities, internal limit is 1000

Save one

VERDEndpointParametersResponseDesc
POST/api/{entities}/save-oneEntityCreateDtoEntityCreate or update an entity, if update parameter must include id field

Save many

VERDEndpointParametersResponseDesc
POST/api/{entities}/save-many{ items: EntityCreateDto[] }Entity[]Create or update many entities, if update parameter must include id field

Update one

VERDEndpointParametersResponseDesc
PATCH/api/{entities}/:idEntityUpdateDtoEntityUpdate one entity by id
POST/api/{entities}/update-one/:idEntityUpdateDtoEntityUpdate one entity by id

Update many

VERDEndpointParametersResponseDesc
POST/api/{entities}/update-many-by-ids{ items: { ids: string, updateDto: EntityUpdateDto }[] }Entity[]Update many entities

Delete one

VERDEndpointParametersResponseDesc
DELETE/api/{entities}/:idEntityDeleteResultDelete one entity by id
POST/api/{entities}/delete-one/:idEntityDeleteResultDelete one entity by id

Delete many

VERDEndpointParametersResponseDesc
POST/api/{entities}/delete-many-by-ids{ ids: string[] }EntityDeleteResultDelete many entities by id