What is OData Service and how to expose one?
The Open Data Protocol is a data access protocol, typically built using RESTful Web Services over Http protocol. Simply, it defines a way to access data from SQL databases, NoSQL and any other data exposed by SaaS applications. With the help of Hybrid Data Pipeline product it is possible to expose OData Services for any datastore that is running in cloud or on-premise with no-code to be written.
Follow this tutorial link to understand how quickly and easily one can expose OData Service using Hybrid Data Pipeline product. Typical URL for your OData Service would be https://<hdp_server>:8443/api/odata4/<your_datasource_name>/
How to access OData Service?
In the previous section, we have seen how to expose an OData Service from Hybrid Data Pipeline product.
In this tutorial, we will create a simple Node.js application and connect to OData Service exposed from Hybrid Data Pipeline to get access to data.
Creating a Node.js application to Connect to OData Service
{ "dependencies": { "@odata/client": "^2.21.0-beta.0" } }
import { OData } from "@odata/client"
console.log('Accessing data using OData Client')
// Hybrid Data Pipeline's sample odata service
const oDataServiceURL = "https://XXXXXXXXXX:8443/api/odata4/sf-royal/$metadata"
const client1 = OData.New4({
metadataUri: oDataServiceURL,
})
client1.setCredential({ username: "d2cadmin", password : "XXXXX" })
let selectLoginIPsByUserID = async () => {
console.log('Executing Query: /LOGINIPS?$format=json$filter=USERSID eq \'00590000002w0IkAAI\'')
// Query by filter
const filter = client1.newFilter().property("USERSID").eq("00590000002w0IkAAI");
let result = await client1.newRequest({ // ODataRequest object
collection: "LOGINIPS", // entity set
params: client1.newParam().filter(filter) // odata param
})
console.log('Executed OData Query (1) successfully.')
console.log(JSON.stringify(result))
}
selectLoginIPsByUserID();
{ "d": {
"results": [
{
"__metadata": [
"Object"
],
"ID": "71090000016dPHRAA2",
"USERSID": "00590000002w0IkAAI",
"SOURCEIP": "202.65.136.5",
"CREATEDDATE": "/Date(1475847693000)/",
"ISAUTHENTICATED": true,
"CHALLENGESENTDATE": null,
"CHALLENGEMETHOD": null
}
]
}
}
4
In the previous sections, we have seen how to expose an OData Service from Hybrid Data Pipeline and consume the same from Node.js. This section outlines how to consume an OData Service from Next.js application.
We still use the same library to connect to OData service and show the results in a web page.
Creating a Next.js application to Connect to OData Service
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@odata/client": "^2.21.2",
"next": "^13.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
References
Hybrid Data Pipeline Installation Guide
On-Premise Connector Installation Guide
Configuring Data Source for OData Access