API Get
![Coverage Status](https://coveralls.io/repos/github/janis-commerce/api-get/badge.svg?branch=master)
A package to handle JANIS Get APIs
Installation
npm install @janiscommerce/api-get
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)
};
}
}
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.