Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
o.js is a isomorphic Odata Javascript library to simplify the request of data. The main goal is to build a standalone, lightweight and easy to understand Odata lib.
o.js is a isomorphic Odata Javascript library to simplify the request of data. The main goal is to build a standalone, lightweight and easy to understand Odata lib.
npm install odata
Or you can use
npm install o.js
which will resolve the same package
import { o } from 'odata';
(async () => {
// chaining
await o('http://my.url')
.get('resource')
.query({ $top: 3 });
// handler
const oHandler = o('http://my.url');
await oHandler
.get('resource')
.query({ $top: 3 });
});
<script src="node_modules/odata/dist/umd/o.js">
It's then placed on the window.odata
:
window.odata
.o('http://my.url')
.get('resource')
.query({ $top: 3 })
.then(function (data) {});
const o = require('odata');
// promise example
await o('http://my.url')
.get('resource')
.then((data) => console.log(data));
You can pass as a second option into the o
constructor options. The signature is:
function o(rootUrl: string | URL, config?: OdataConfig | any)
Basic configuration is based on RequestInit and additional odata config. By default o.js sets the following values:
{
batch: {
changsetBoundaryPrefix: "changset_",
endpoint: "$batch",
headers: new Headers({
"Content-Type": "multipart/mixed",
}),
useChangset: false,
},
boundaryPrefix: "batch_",
credentials: "omit",
fragment: "value",
headers: new Headers({
"Content-Type": "application/json",
}),
mode: "cors",
redirect: "follow",
referrer: "client",
}
The following query options are supported by query()
, fetch()
and batch()
by simply adding them as object:
$filter?: string;
$orderby?: string;
$expand?: string;
$select?: string;
$skip?: number;
$top?: number;
$count?: boolean;
$search?: string;
$format?: string;
$compute?: string;
$index?: number;
[key: string]: any; // allows to add anything that is missing
The queries are always attached as the URLSearchParams.
The lib tries to parse the data on each request. Sometimes that is not wanted (e.g. when you need a status-code or need to access odata meta data), therefor you can use the .fetch
method that acts like the default fetch.
By default o.js request chained request in sequent. You can batch them together by using batch()
. They are then send to the defined batch endpoint in the config. Changsets are at the moment in a experimental phase and needs to be enabled in the config.
Polyfills are automatically added for fetch()
and URL()
if needed. The automatic polyfilling can be disabled in the options.
FAQs
o.js is a isomorphic Odata Javascript library to simplify the request of data. The main goal is to build a standalone, lightweight and easy to understand Odata lib.
The npm package odata receives a total of 1,755 weekly downloads. As such, odata popularity was classified as popular.
We found that odata demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.