HTTP Protocol for Barnard59 Linked Data Pipelines

2.1.0 · active · verified Wed Apr 22

barnard59-http provides a set of HTTP protocol operations (such as GET, POST, PUT, DELETE) that function as 'steps' within Barnard59 Linked Data pipelines. Barnard59 is an Extract, Transform, Load (ETL) toolkit primarily designed for working with RDF and Linked Data, where pipelines are declaratively defined using RDF graphs (e.g., in Turtle or JSON-LD format) and executed by the `barnard59` CLI or programmatic API. This package extends the core Barnard59 functionality, enabling pipelines to interact with external HTTP resources. The current stable version is 2.1.0, and it is part of an actively maintained monorepo, with frequent patch and minor releases across its constituent packages. Key differentiators include its deep integration with RDF/Linked Data principles, its streaming architecture for handling large datasets, and the flexibility to embed custom JavaScript logic directly into RDF-defined pipelines.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates defining an RDF pipeline in Turtle (.ttl) to fetch JSON data via an `http:get` step and process it with a custom TypeScript step. It showcases integration within the Barnard59 ecosystem and execution via the `barnard59` CLI.

/* pipeline.ttl */
@prefix pipeline: <https://pipeline.described.at/> .
@prefix p: <http://barnard59.com/pipeline/> .
@prefix http: <http://barnard59.com/http/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/pipeline/fetchData> a p:Pipeline ;
  rdfs:label "Fetch JSON data from an API" ;
  pipeline:runs (
    [ a http:get ;
      http:url "https://jsonplaceholder.typicode.com/todos/1"^^xsd:anyURI ;
      rdfs:label "Fetch Todo 1"
    ]
    [ a p:map ;
      rdfs:label "Parse JSON and extract title" ;
      pipeline:handle <node:./transform.js#parseJsonAndExtractTitle>
    ]
    [ a p:catch ;
      rdfs:label "Handle Errors"
      pipeline:handle <node:./transform.js#logError>
    ]
  ) .

/* transform.ts */
import { Context, Stream } from '@barnard59/core';

export function parseJsonAndExtractTitle(this: Context, chunk: Stream) {
  const content = chunk.toString(); // Assuming the HTTP response is a string
  try {
    const json = JSON.parse(content);
    return this.env.rdf.literal(json.title || 'No Title');
  } catch (error) {
    console.error('Failed to parse JSON or extract title:', error);
    return this.env.rdf.literal('Error processing data');
  }
}

export function logError(this: Context, error: Error) {
  console.error('Pipeline error caught:', error.message);
  return this.env.rdf.literal(`Error: ${error.message}`);
}

/* Usage with barnard59 CLI: */
// npm install -g barnard59
// npm install barnard59-http @barnard59/core @zazuko/env
// barnard59 run pipeline.ttl --pipeline http://example.org/pipeline/fetchData

view raw JSON →