Implementing Pipes2 Endpoint for Single Item Feed
Introduction
In a similar way to other Pipes2 Endpoints, Zapp provides the ability to load a feed which its response is expected to provide additional information on an Entry (a Video item for example). In some cases your API will require additional requests to specific item to provide this additional information. Few examples could be to secure stream sources, provide additional DRM information, authorize users, send additional metadata, etc. In order to support these capabilities, your REST API should provide an endpoint to fetch a single-entry feed.
Pipes2 Simple Endpoint Example
The following is a simple Pipes2 Single Feed Entry Endpoint implemented with expressjs that returns the
static Pipes Feed JSON with 1 entry that is stored in the feed.json file (shown below).
const express = require("express");
const app = express();
const port = 8080;
app.get("/example/items/:itemId", (req, res) => {
const item = getItemById(req.params.itemId); // call to your db
const signedStreamURL = sign(item.streamURL); // call to your signer service
var context = JSON.parse(base64url.decode(req.query.ctx));
const drmKey = getDrmKey(item.streamURL, context["access_token"]); // get your DRM data
const feed = renderFeed(item, {
signedStreamURL: signedStreamURL,
drmKey: drmKey,
}); // call to your render feed function
res.set("Content-Type", "application/vnd+applicaster.pipes2+json").send(feed);
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
Example JSON:
{
"id": "https://www.example.com/path/of/example/endpoint/myFeedID",
"type": { "value": "feed" },
"title": "Example feed",
"entry": [
{
"id": "89123456701",
"title": "Example Video",
"summary": "Action · 149 Mins",
"updated": "2019-11-15T10:41:03+00:00",
"published": "2019-11-15T10:31:00+00:00",
"type": { "value": "video" },
"content": {
"src": "https://www.example.com/path/to/example/video.m3u8",
"type": "video/hls"
},
"link": {
"rel": "self",
"href": "https://www.example.com/items/89123456701"
},
"extensions": {
"free": true,
"section": "JUST ADDED",
"duration": 9863,
"drm": {
"widevine": {
"license_url": "your_license_url",
"extensions": {
"custom_data": "..",
"integration": "keyos"
}
}
//...//
}
},
"media_group": [
{
"type": "image",
"media_item": [
{
"key": "thumbnail",
"src": "https://www.example.com/path/to/example/image.jpg"
}
]
}
]
}
]
}