NatLibFi / sru-client-js

SRU Javascript client library
MIT License
7 stars 5 forks source link

SRU Javascript client library NPM Version

This library implements a client to retrieve records via Search/Retrieve via URL (SRU) API.

Usage

Retrieve all records

import createClient from '@natlibfi/sru-client';
const client = createClient({url: 'https://foo.bar', recordSchema: 'marcxml'});

client.searchRetrieve('foo')
  .on('record', record => processRecord(string))
  .on('total', totalNumberOfRecords => doSomething(totalNumberOfRecords))
  .on('end', () => endProcessing())
  .on('error', err => handleError(err));

Retrieve records only from the first response

import createClient from '@natlibfi/sru-client';
const client = createClient({url: 'https://foo.bar', recordSchema: 'marcxml', retrieveAll: false});

client.searchRetrieve('foo')
  .on('record', record => processRecord(record))
  .on('total', totalNumberOfRecords => doSomething(totalNumberOfRecords))
  .on('end', nextRecordOffset => endProcessing(nextRecordOffset))
  .on('error', err => handleError(err));

Retrieve total amount of records

import createClient from '@natlibfi/sru-client';
const client = createClient({url: 'https://foo.bar', recordSchema: 'marcxml', maxRecordsPerRequest: 0, retrieveAll: false});

client.searchRetrieve('foo')
  .on('total', totalNumberOfRecords => doSomething(totalNumberOfRecords))
  .on('end', () => endProcessing())
  .on('error', err => handleError(err));

Configuration

Client creation options

searchRetrieve options:

The first parameter is the mandatory CQL query string. Second is an optional object which supports the following properties:

Notes

License and copyright

Copyright (c) 2015, 2017-2018, 2020-2024 University Of Helsinki (The National Library Of Finland)

This project's source code is licensed under the terms of MIT.