API: Database Endpoints
Relevant source files
The following files were used as context for generating this wiki page:
- src/pages/database/data.json.ts
- src/pages/database/data-index.json.ts
- src/pages/career-paths/[path]/data.json.ts
- src/pages/career-paths/[path]/data-index.json.ts
- src/components/astro/database/reactive-datatable.tsx
- src/content.config.ts
- src/types/certification-metadata.ts
- src/pages/database/fuse.config.ts
The CyberPath application utilizes a set of server-side generated JSON endpoints to provide data to its frontend components. These endpoints, built with Astro, serve pre-compiled information about cybersecurity certifications, which are sourced from Markdown files within the content collection. This approach ensures that the data is static, fast to load, and easily consumable by client-side components like the reactive data table.
The primary purpose of these API endpoints is to decouple the data layer from the presentation layer. They provide the full dataset of certifications as well as pre-computed search indexes using Fuse.js, which enables efficient client-side searching without needing a backend database. The API is divided into two main categories: general database endpoints and career-path-specific endpoints.
Core Data Endpoints
These endpoints provide the complete dataset for all cybersecurity certifications managed in the content collection.
GET /database/data.json
This endpoint returns a JSON array containing the metadata for all published certifications. It is the primary source of data for the main database page.
The data generation process is handled by the getCertificationMetadata function. This function uses Astro's getCollection API to retrieve all entries from the certifications content collection. It filters out any entries marked as draft: true and then maps the remaining data to the CertificationMetadata structure. This mapping includes adding derived fields like provider (from the file path) and slug.
Sources: src/pages/database/data.json.ts:10-29
The following diagram illustrates the data flow for generating data.json:
Diagram showing the process of fetching, filtering, and transforming certification data.
Sources: src/pages/database/data.json.ts:10-34
GET /database/data-index.json
To facilitate fast client-side searching, this endpoint provides a pre-computed Fuse.js search index. Instead of the client fetching all data and building the index, it can download this smaller, optimized JSON file.
The endpoint uses the getCertificationMetadata function to fetch the certification data and then passes it to Fuse.createIndex. The configuration for the index, including which keys to index, is defined in fuse.config.ts. The resulting index is then serialized to JSON and returned in the response.
Sources: src/pages/database/data-index.json.ts:8-15, src/pages/database/fuse.config.ts
The generation process for the search index is as follows:
Diagram showing the creation of the pre-computed Fuse.js search index.
Sources: src/pages/database/data-index.json.ts:8-15
Career Path Endpoints
These are dynamically generated endpoints that provide certification data filtered by a specific career path. The available paths are determined by getStaticPaths which maps the CareerPathsList to kebab-case URL slugs.
Sources: src/pages/career-paths/[path]/data.json.ts:11-23
GET /career-paths/[path]/data.json
This endpoint returns a JSON array of certifications that are relevant to a specific career path, identified by the [path] parameter in the URL.
It uses a lookup table to convert the URL slug (e.g., blue-team-specialist) back to the full career path name (e.g., "Blue Team Specialist"). This name is then used in a filter function passed to getCertificationMetadata, which ensures only certifications containing that career path in their career_paths array are returned.
Sources: src/pages/career-paths/[path]/data.json.ts:39-43
GET /career-paths/[path]/data-index.json
Similar to the global data-index.json, this endpoint provides a pre-computed Fuse.js search index, but only for the certifications belonging to the specified career path. This allows for scoped, efficient searching on career path pages.
The logic is nearly identical to the global index endpoint but applies the career path filter when fetching the initial data via getCertificationMetadata.
Sources: src/pages/career-paths/[path]/data-index.json.ts:15-22
Data Structures
Certification Schema
The core data object for a certification is defined by the certifications collection schema and the CertificationMetadata type. The data is sourced from Markdown frontmatter.
Sources: src/content.config.ts:8-21, src/types/certification-metadata.ts:1-13
The following table details the fields in the final CertificationMetadata object returned by the API.
| Field | Type | Description | Source File |
|---|---|---|---|
title | string | The full title of the certification. | src/content.config.ts:12 |
acronym | string | The acronym for the certification. | src/content.config.ts:13 |
last_updated_at | Date | The date the certification information was last updated. | src/content.config.ts:14 |
image | string | The source path to the certification's image. | src/pages/database/data.json.ts:25 |
reference | string | A URL to the official certification page. | src/content.config.ts:16 |
aliases | string[] | An optional array of alternative names or acronyms. | src/content.config.ts:17 |
career_paths | string[] | An array of career paths this certification is relevant to. | src/content.config.ts:19 |
price | string | The price of the certification exam or materials. | src/content.config.ts:20 |
currency | string | The currency for the price (e.g., "USD"). | src/content.config.ts:21 |
provider | string | The organization providing the certification. Derived from the content file's parent directory and title-cased. | src/pages/database/data.json.ts:26 |
slug | string | The unique identifier for the certification, used in URLs. Derived from the content file path. | src/pages/database/data.json.ts:27 |
Client-Side Consumption
The primary consumer of these API endpoints is the ReactiveDatatable React component, which provides a searchable and paginated view of the certifications.
ReactiveDatatable Component
On initialization, the ReactiveDatatable component fetches both the full dataset from /data.json and the pre-computed search index from /data-index.json.
The component uses Promise.all to fetch both resources concurrently. Once the data and index are loaded, it initializes a new Fuse instance with the data, the pre-computed index, and the shared FuseConfig. This setup allows for extremely fast client-side filtering and searching based on user input.
Sources: src/components/astro/database/reactive-datatable.tsx:160-163
The following sequence diagram shows the data loading and initialization flow for the ReactiveDatatable component.
Sequence diagram illustrating how the ReactiveDatatable component fetches and initializes its data and search functionality.
Sources: src/components/astro/database/reactive-datatable.tsx:160-197
Summary
The database API endpoints in CyberPath provide a robust and performant system for serving certification data to the frontend. By pre-building the data and search indexes into static JSON files, the application ensures fast load times and a responsive user experience for searching and browsing certifications. The separation of concerns between general and career-path-specific endpoints allows for tailored data delivery, while the ReactiveDatatable component demonstrates an effective pattern for consuming this data on the client side.