legal-docs-client
v1.0.0
Published
TypeScript client for accessing legal documents from the Case Law Explorer API
Maintainers
Readme
Legal Docs Client
A TypeScript client library for accessing legal documents from the Case Law Explorer API.
Each data source is exposed through its own typed endpoint: Rechtspraak (Dutch case law) and ECHR (European Court of Human Rights).
Installation
npm install legal-docs-clientUsage
Basic Setup
import { createLegalDocsClient } from 'legal-docs-client';
const client = createLegalDocsClient({
apiKey: process.env.CITATIONS_API_KEY
});Fetching Rechtspraak Documents
fetchRechtspraak queries Dutch case law (Rechtspraak) citation networks:
const documents = await client.fetchRechtspraak({
degreesSource: 0,
degreesTarget: 0,
dateStart: "1900-01-01",
dateEnd: "2026-03-10",
docTypes: ["DEC"],
attributesToFetch: "ALL",
keywords: ["armenia"],
selectedLawsIntersect: true,
});
console.log(documents);Fetching Documents with Statistics
You can automatically compute statistics for the fetched documents by passing true as the second parameter:
const documents = await client.fetchRechtspraak({
degreesSource: 1,
degreesTarget: 1,
dateStart: "2020-01-01",
dateEnd: "2024-12-31",
docTypes: ["DEC"],
eclis: ["ECLI:NL:HR:2021:1234"],
}, true); // computeStatistics = true
// Each document will have a statistics property with centrality metrics
console.log(documents[0].data.statistics);
/*
{
parent: "ECLI:NL:HR:2021:1234",
degree: 5,
inDegree: 2,
outDegree: 3,
degreeCentrality: 0.8,
inDegreeCentrality: 0.4,
outDegreeCentrality: 0.6,
betweennessCentrality: 0.5,
closenessCentrality: 0.7,
relativeInDegree: 0.4,
community: 0,
year: 2021,
pageRank: 0.25
}
*/Computing Statistics
You can compute network statistics (centrality metrics) for a set of documents:
// First, fetch some documents
const documents = await client.fetchRechtspraak({
degreesSource: 1,
degreesTarget: 1,
eclis: ["ECLI:NL:HR:2021:1234"],
});
// Then compute statistics
const statistics = await client.computeStatistics(documents);
console.log(statistics);
/*
[
{
id: "ECLI:NL:HR:2021:1234",
parent: "ECLI:NL:HR:2020:5678",
degree: 5,
inDegree: 2,
outDegree: 3,
degreeCentrality: 0.8,
inDegreeCentrality: 0.4,
outDegreeCentrality: 0.6,
betweennessCentrality: 0.5,
closenessCentrality: 0.7,
relativeInDegree: 0.4,
community: 0,
year: 2021,
pageRank: 0.25
},
// ... more statistics for other documents
]
*/The statistics include various centrality measures:
- degree: Total number of connections (citations + cited by)
- inDegree: Number of documents citing this one
- outDegree: Number of documents this one cites
- degreeCentrality: Normalized degree centrality
- inDegreeCentrality: Normalized in-degree centrality
- outDegreeCentrality: Normalized out-degree centrality
- betweennessCentrality: Measure of how often a document lies on the shortest path between other documents
- closenessCentrality: Measure of how close a document is to all other documents
- relativeInDegree: Ratio of in-degree to total degree
- pageRank: PageRank score indicating importance in the citation network
- community: Community/cluster identifier
- year: Year from the document's decision date
Getting Full Text
const fullTextDocs = await client.getRechtspraakFullText(['ECLI:NL:HR:2005:AO9006', 'ECLI:NL:RBSGR:2012:BY5532']);
console.log(fullTextDocs);
// [{ ecli, fullText, fullTextAvailable, message? }, ...]Fetching ECHR Documents
fetchEchr queries HUDOC (European Court of Human Rights) citation networks. At least one search criterion (keyword, ECLI, application number, or article) is required:
const documents = await client.fetchEchr({
degreesSource: 1,
degreesTarget: 1,
keywords: ["Armenia"],
attributesToFetch: "MINIMAL",
});
console.log(documents);Filter by violated/applied articles and respondent state:
const documents = await client.fetchEchr({
degreesSource: 1,
degreesTarget: 1,
article_violated: ["6", "8"],
article_violated_mode: "OR",
respondent_state: ["GRC"],
pageSize: 100,
});Statistics can be computed the same way as for Rechtspraak, by passing true as the second parameter, or afterwards via client.computeStatistics(documents).
Getting ECHR Full Text
const fullTextDocs = await client.getEchrFullText(['ECLI:CE:ECHR:2000:1026JUD003098596']);
console.log(fullTextDocs);
// [{ ecli, language, itemid, fullText, fullTextAvailable, message?, languages? }, ...]By default the API picks a language (English preferred, then French) and returns every available language version in languages. Request a specific language instead:
const fullTextDocs = await client.getEchrFullText(
['ECLI:CE:ECHR:2000:1026JUD003098596'],
'FRE',
);Fetching Laws
const laws = await client.fetchLaws('Art. 7:669 BW');
console.log(laws);Environment Configuration
This package requires an API token from the Case Law Explorer API for document requests.
Setup Instructions
- Install dotenv (if working in Node.js):
npm install dotenv- Create a
.envfile in your project root:
CITATIONS_API_KEY=your_api_token_here- Load environment variables in your application:
import 'dotenv/config';
import { createLegalDocsClient } from 'legal-docs-client';
const client = createLegalDocsClient({
apiKey: process.env.CITATIONS_API_KEY
});Note: For Vite projects, use
import.meta.env.VITE_CITATIONS_API_KEYinstead and prefix your.envvariable withVITE_.
Getting an API Token
New API keys can be generated at: https://api.caselawexplorer.tech/login.html?next=/account.html
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
