ASP.NET 8 Web API that serves Croissant 1.0 JSON-LD responses from a SQLite/PostgreSQL database of Chichewa metadata.
llrp-api/
├── Controllers/
│ └── DatasetsController.cs # GET /api/datasets/query + /health
├── Data/
│ ├── AppDbContext.cs # EF Core context
│ └── Models/Models.cs # Dataset, FileRecord, Keyword, Theme
├── DTOs/
│ └── DatasetQueryParams.cs # Query string parameters
├── Middleware/
│ └── ApiKeyMiddleware.cs # X-Api-Key enforcement
├── Services/
│ ├── FileQueryService.cs # DB query + random sampling
│ └── CroissantBuilder.cs # JSON-LD serialiser
├── appsettings.json # Connection string + API keys (production)
├── appsettings.Development.json # Overrides for local dev
└── Program.cs # DI + middleware pipeline
Edit appsettings.json (or use User Secrets / environment variables in production):
{
"ApiKeys": [
"your-secret-key-here"
]
}Environment variable override (no quotes needed):
ApiKeys__0=your-secret-key-here
ApiKeys__1=another-key
cd llrp-api
dotnet runThe API starts on https://localhost:5001 / http://localhost:5000.
Open http://localhost:5000/swagger in your browser.
- Click Authorize (top right)
- Enter your API key (e.g.
dev-key-12345) - Click Authorize → Close
- All requests from Swagger UI will now include the
X-Api-Keyheader
Returns a Croissant JSON-LD document. All parameters are optional.
| Parameter | Type | Default | Description |
|---|---|---|---|
| keyword | string | — | Partial, case-insensitive keyword match |
| theme | string | — | Partial, case-insensitive UNBIS theme match |
| author | string | — | Partial, case-insensitive author name match |
| year | string | — | Exact year, e.g. 2024 |
| limit | int | 30 | Max files in response (1–100). Random sample taken when total > limit |
Example requests:
# All files tagged with "malaria", limit 10
curl -H "X-Api-Key: dev-key-12345" \
"http://localhost:5000/api/datasets/query?keyword=malaria&limit=10"
# Health and Education files from 2024
curl -H "X-Api-Key: dev-key-12345" \
"http://localhost:5000/api/datasets/query?theme=Health&year=2024"
# Combine filters
curl -H "X-Api-Key: dev-key-12345" \
"http://localhost:5000/api/datasets/query?keyword=election&theme=Political&author=Banda&limit=5"Returns API status and total file count. Also requires X-Api-Key.
curl -H "X-Api-Key: dev-key-12345" http://localhost:5000/api/datasets/health- API keys live in
appsettings.json→ApiKeysarray - In production, inject keys via environment variables or a secrets manager — never commit real keys to source control
- Swagger UI is exempt from the key gate so the docs page loads freely, but every API call made through it still requires a valid key
- Consider rate limiting (e.g.
AspNetCoreRateLimitpackage) for public-facing deployments
{ "@context": [ "https://mlcommons.org/working-groups/data/croissant/", { ... } ], "generatedAt": "2026-02-27T10:00:00Z", "samplingInfo": { "totalMatched": 120, // files that matched the query "limit": 30, // requested limit "returned": 30, // files in this response "randomSample": true // true when totalMatched > limit }, "@graph": [ { "@type": "sc:Dataset", "@id": "DDP-NATION-2024", "scName": "Nation Newspaper 2024", "distribution": [ { "@type": "cr:FileObject", "@id": "file-2024-abc123", "scName": "Nation_On_Sunday_20240315_p001.pdf", "scKeywords": ["malaria", "hospital"], "dcatTheme": ["Health"], ... } ] } ] }