5.1.0 • Published 1 year ago

@ovh-ux/ng-ovh-api-wrappers v5.1.0

Weekly downloads
414
License
BSD-3-Clause
Repository
github
Last release
1 year ago

ng-ovh-api-wrappers

AngularJS component designed to configure Api Endpoints with the same interface as a $resource yet allow for extended configuration by providing ApiRequests objects that can be modified with chained methods to define the headers to Iceberg.

Downloads Dependencies Dev Dependencies

Install

$ yarn add @ovh-ux/ng-ovh-api-wrappers

Usage

// index.js
import angular from 'angular';
import ngOvhApiWrappers from '@ovh-ux/ng-ovh-api-wrappers';

angular.module('myApp', [ngOvhApiWrappers]);

Iceberg

Simple request

// service.js
function getElements() {
  return iceberg('/api/elements')
    .query()
    .execute({ ...queryParams }, resetCache)
    .$promise;
}

Response is formatted like

{
  data // data returned by the API
  headers // response headers returned
  status // call status
}

Enable aggregation

// service.js
function getAggregatedElements() {
  return iceberg('/api/elements')
    .query()
    .expand(aggregationMode)
    .execute();
}

aggregationMode can be one of those values:

  • CachedObjectList-Cursor
  • CachedObjectList-Pages

Paginate

// service.js
function getPaginatedElements() {
  return iceberg('/api/elements')
    .query()
    .expand('CachedObjectList-Pages')
    .limit(10) // get only 10 results by page
    .offset(2) // get results for page 2
    .execute();
}

Filter

// service.js
function getFilteredElements() {
  return iceberg('/api/elements')
    .query()
    .expand('CachedObjectList-Pages')
    .addFilter('name', 'like', 'iceberg') // get element with name matching iceberg
    .execute();
}
// service.js
function getFilteredElements() {
  return iceberg('/api/elements')
    .query()
    .expand('CachedObjectList-Pages')
    .addFilter('name', 'like', ['iceberg', 'awesome']) // get element with name matching iceberg and awesome
    .execute();
}

Sort

// service.js
function getSortedElements() {
  return iceberg('/api/elements')
    .query()
    .expand('CachedObjectList-Pages')
    .sort('name') // sort elements by ascending names
    .execute();
}
// service.js
function getAggregatedElements() {
  return iceberg('/api/elements')
    .query()
    .expand('CachedObjectList-Pages')
    .sort('name', 'desc') // sort elements by descending names
    .execute();
}

Test

$ yarn test

Related

Contributing

Always feel free to help out! Whether it's filing bugs and feature requests or working on some of the open issues, our contributing guide will help get you started.

License

BSD-3-Clause © OVH SAS

5.1.0

1 year ago

5.0.0

2 years ago

4.0.11

2 years ago

4.0.9

2 years ago

4.0.10

2 years ago

4.0.8

4 years ago

4.0.7

4 years ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

5 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.0

5 years ago