Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.law4devs.eu/llms.txt

Use this file to discover all available pages before exploring further.

Setup

import { Law4DevsClient } from 'law4devs';

const client = new Law4DevsClient();

1. List all frameworks

const page = await client.frameworks.list({ perPage: 50 });

console.log(`${page.meta.total} frameworks available`);

for (const fw of page.data) {
  const label = fw.status === 'active' ? fw.shortName : `${fw.shortName} (${fw.status})`;
  console.log(`${label}: ${fw.name}`);
}

2. Iterate all CRA articles

Use for await to walk through every article without managing pagination manually.
let count = 0;

for await (const article of client.articles.iter('cra')) {
  console.log(`Art. ${article.articleNumber}: ${article.title}`);
  count++;
}

console.log(`Iterated ${count} CRA articles`);
iter() fetches pages lazily. Break out of the loop early with break as soon as you have what you need — subsequent pages are never fetched.

3. Search with a framework filter

const results = await client.search.query('security requirements', {
  framework: 'nis2',
  resultType: 'article',
  perPage: 10,
});

for (const result of results.data) {
  console.log(`[${result.type}] Art. ${result.articleNumber}: ${result.title}`);
  console.log(`  ...${result.matchContext}...`);
}

4. Get compliance deadlines with iterDeadlines()

for await (const deadline of client.compliance.iterDeadlines({ frameworkSlug: 'nis2' })) {
  const date = deadline.deadlineDate ?? 'ongoing';
  console.log(`${deadline.deadlineType}${date}: ${deadline.description}`);
}
The compliance resource uses iterDeadlines() rather than iter() because it operates across multiple frameworks rather than within a single one.

5. Error handling

import { Law4DevsClient, NotFoundError, RateLimitError } from 'law4devs';

const client = new Law4DevsClient({ maxRetries: 3 });

try {
  const article = await client.articles.get('gdpr', 999);
  console.log(article.title);
} catch (err) {
  if (err instanceof NotFoundError) {
    console.error(`Article not found (HTTP ${err.statusCode})`);
  } else if (err instanceof RateLimitError) {
    console.error('Rate limit hit — the SDK retries automatically, but all retries were exhausted');
  } else {
    throw err; // re-throw unexpected errors
  }
}

Next Steps

Frameworks →

Articles →

Pagination →

Error Handling →