1.1.1 • Published 5 years ago

odcj v1.1.1

Weekly downloads
-
License
Apache 2.0
Repository
github
Last release
5 years ago

OData Logo

ODCJ - OData Connector For Javascript

The OData Connector For Javascript or more formerly know as ODCJ, is a promise based client that uses axios to establish connections to OData V3/V4 services.

What's new in 1.1.1 🆕

  • Added Connector.head and Connector.options HTTP method functions.
  • Refractored the Connector.class and FilterExpression.class to object/function style.
  • Renamed the Connector.remove method to Connector.delete.

Started developing webhook subscriptions for requests, will probably be released with version 1.2.0. This will allow to make requests when certain url's give specific responses.

Installation ⏳

You can install the odjc package with yarn from npm

yarn add odjc

or with npm

npm install odjc

Once you have installed the dependency for ODCJ install all dependencies.

yarn

or with npm

npm install

Getting started 🚀

The most basic way of using ODCJ is to import the Provider class and creating a Connector with the createConnector() method.

// import the Provider class
import { Provider } from 'odcj';

// this is the base url without the actual endpoint
const Connector = new Provider('https://example.com/OData/v4');
  .createConnector();
  
Connector
  .get('/items')
  .then(response => {
    console.log(response.data);
  })
  .catch((err) => {
    console.log(err.message);
  });

Adding authentication 🔒

To add authentication you can use the addAuth() method. There are currently two supported modes 'basic' with username and password or 'Bearer' with a JWT or API Token.

const Connector = new Provider('https://example.com/OData/v4');
  .addAuth('basic', { username: 'john', password: 'secret' })
  .addAuth('bearer', { token: 'mytoken' })
  .createConnector();

Using filters 🔎

You may want to filter your results via the $filter paramter. We provide the FilterExpression class, just import it into the project alongside the Provider class.

import { Provider, FilterExpression } from 'odcj';

// create a new filter expression. Would be equal to ($filter=No eq 1)
const FilterByNo = FilterExpression('No', 'eq', '1');

// create a new filter expression with and or or. Would be equal to (or No eq 1)
const FilterByNoOr = FilterExpression('No', 'eq', '1', 'or');

// you can also use the filter functions provided by OData
const FilterByNoFunction = FilterExpression('No', 'startswith()', '1', 'and');

// some functions take more than one argument, for example: ceil(Field, Value) eq Value
// in this case you could pass an array to the operator and value argumments.
const FilterByNoFunctionMultiParam = FilterExpression('No', ['ceil()', 'eq'], ['1', '4'], 'or');

When you have created your filters you can easly add them to your Provider.

const Connector = new Provider('https://example.com/OData/v4');
  .addFilter([ FilterByNo, FilterByNoOr, FilterByNoFunction, FilterByNoFunctionMultiParam ])
  .createConnector();

Adding pagination 🔢

When you have created a connector you can manipulate the $skip and $top paramters by calling the setTop() and setSkip() methods on the Connector.

// create a connector using createConnector()
const Connector = new Provider('https://example.com/OData/v4');
  .createConnector();

// call the relevant methods
Connector.setTop(10);
Connector.setSkip(10);

Custom query parameters

If you need to add custom query paramters you can use our addQueryString() method to do so.

const Connector = new Provider('https://example.com/OData/v4');
  .addQueryString('paramName', 'paramValue');
  .createConnector();

Legal ⚖️

This Project is NOT in any way affiliated with the creators of OData or © 2015-2018 OData – The Protocol for REST APIs. Any logos used are property of the rightful owner and are not beeing claimed as ones own property from the developer.

License

Copyright 2019 Fabio Nettis

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago