API Get
A package to handle JANIS Get APIs
Installation
npm install @janiscommerce/api-get
⚠️ Breaking changes from version 3.0.0 ⚠️
Since 3.0.0
API upgraded to v5. API Session store validations replaced with loactions
For more information see API and API Session
Usage
'use strict';
const { ApiGet } = require('@janiscommerce/api-get');
class MyApiGet extends ApiGet {
get fieldsToSelect() {
return [
'id',
'name',
'status'
];
}
async format(record) {
return {
...record,
oneMoreField: true
};
}
_parseFilters({ id, ...otherFilters }) {
return {
...otherFilters,
id: Number(id)
};
}
async postGetValidate({ name }) {
if(name === FORBIDDEN_NAME) {
this.setCode(403);
throw new Error('Forbidden name');
}
}
}
module.exports = MyApiGet;
All methods are optional
Get APIs with parents
If you have for example, a get API for a sub-entity of one specific record, the parent will be automatically be added as a filter.
For example, the following endpoint: /api/parent-entity/1/sub-entity/2
, will be a get of the sub-entity, and parentEntity: '1'
will be set as a filter.