pub-src-http
v2.0.0
Published
HTTP source for pub-server and pub-generator - uses built-in fetch in node and browser
Downloads
69
Readme
pub-src-http
HTTP source for pub-server and pub-generator
- provides
get()
andput()
for JSON reads and writes over http - uses built-in fetch in browser (requires node v18 or later)
src(options)
var src = require('pub-src-http');
// instantiate source
// options become properties of source
var source = src( { path:'https://....' } );
source.get(function(err, result) {
if (err) return console.log(err);
console.log(result);
});
source.path
- must be set to the URL of the HTTP endpoint
source.timeout
- not currently implemented
source.get([options], cb)
get()
fetches JSON in a single HTTP GET request from the endpoint in source.path- the result should be an array of file objects each with a
path:
and atext:
property - for non "PUB" type sources, other JSON structures may be retrieved
source.put(files, [options], cb)
- does nothing unless
writable
is set on the source - serializes files into JSON and transmits them via HTTP POST to the endpoint in source.path
options
- use optional options object for fetch options like headers
- use options.url to override endpoint
source.put(files, function(err, result) {
if (err) return console.log(err);
console.log(result);
});
configuring authentication
- explicit authentication configuration is not currently supported
- in the browser request cookie credentials are included