Resume JSON API
Relevant source files
The following files were used as context for generating this wiki page:
The Resume JSON API provides a programmatic interface to retrieve resume data stored in the project's content collections. It exposes endpoints to fetch the entire resume dataset or specific filtered sections such as experience, skills, or education.
The system processes YAML source files located in src/content/resume/ and transforms them into structured JSON responses. This API supports static site generation through dynamic route parameters and validates data against a Zod-based schema.
Sources: src/pages/api/resume.json.ts, src/pages/api/resume/[section].json.ts, src/features/resume/resume.server.ts
API Endpoints
The API consists of two primary GET endpoints handled as Astro API routes.
Get Entire Resume
GET /api/resume.json
This endpoint retrieves the complete resume object. It aggregates all files from the resume collection, assembles them into a nested object, and sorts entries by date.
Sources: src/pages/api/resume.json.ts:5-13
Get Resume Section
GET /api/resume/[section].json
This endpoint retrieves a specific section of the resume (e.g., experience, skills). It uses dynamic routing to identify the requested section and returns a 404 status if the section does not exist.
Sources: src/pages/api/resume/[section].json.ts:31-52
| Endpoint | Method | Parameter | Description |
|---|---|---|---|
/api/resume.json | GET | None | Returns the full structured resume. |
/api/resume/[section].json | GET | section | Returns data for a specific resume category. |
Data Flow and Architecture
The API follows a layered architecture: the route handler calls the server-side loader, which utilizes utility functions to process and assemble raw collection entries.
The sequence below illustrates how a request for a specific section is handled:
Content Processing and Assembly
The system converts flat file structures into a nested resume hierarchy. Files at the top level of the collection directory become direct keys in the result object. Files in subdirectories are nested and grouped.
Assembly Logic
- Parsing: The
parseContentIdfunction identifies if an entry is top-level or part of a nested section. - Assignment: Entries are assigned to the
resultobject. Subdirectory items are stored in arrays under the section key. - Sorting:
experienceentries usesortExperienceByEndDate.- Other arrays use
sortByDateDesc.
Sources: src/features/resume/resume.utils.ts:15-42
Schema Validation
The createResumeSchema function defines the shape of resume entries using Zod. It handles multiple data types including objects for basic info and arrays for skills or awards.
export function createResumeSchema() {
return z.union([
experienceSchema,
educationSchema,
awardSchema,
basicsSchema,
z.array(z.object({ category: z.string(), items: z.array(z.string()) })),
z.array(educationSchema),
z.array(communitySchema),
z.array(awardSchema),
z.array(z.string()),
])
}
Sources: src/features/resume/resume.schema.ts:101-113
Static Path Generation
For the dynamic [section].json route, Astro generates static paths at build time. The getStaticPaths function scans the resume collection and extracts unique section names from file paths to create the available API routes.
Sources: src/pages/api/resume/[section].json.ts:11-25
Summary
The Resume JSON API provides a structured, validated way to access resume data. It centralizes content processing through the resume.server.ts and resume.utils.ts modules, ensuring that both full and partial data requests receive consistently formatted and sorted results.