@biblioteksentralen/oai-pmh-client
v0.0.2
Published
OAI-PMH client
Downloads
5
Keywords
Readme
@biblioteksentralen/oai-pmh-client
Usage
import { OaiPmhClient } from "@biblioteksentralen/oai-pmh-client";
import { pino } from "pino";
const log = pino(); // Any logger implementing the TypeScript Abstract Logger interface can be used.
const oaiPmhClient = new OaiPmhClient({
url: "https://stord.bib.no/cgi-bin/oai",
metadataPrefix: "marc21",
log,
});
const options = { from: "2023-05-10" };
for await (const { record } of oaiPmhClient.listRecords(options)) {
console.log(`Fetched record ${record.header.identifier}`);
// doSomethingWithRecord(response.record)
}
The listRecords()
method is implemented as an async generator and handles resumption and automatic retries under the hood. Custom timeout and retry options can be set when constructing the client. For example, to disable automatic retries, set attempts
to 1
:
const oaiPmhClient = new OaiPmhClient({
url: "https://stord.bib.no/cgi-bin/oai",
metadataPrefix: "marc21",
log,
retry: { attempts: 1 },
});
Error handling
If we receive an error from the OAI-PMH server, a OaiPmhError
error will be raised, containing the OAI-PMH error. These are typically returned for invalid argument values or other client errors.