This is an example of pairing an OpenAPI/Swagger-documented backend with a CrootJS
frontend. The spec below (openapi.yaml) describes a
small example API; usage.js shows the matching
getJSON/postJSON/putJSON/deleteJSON
calls from api.js. Fork this folder and
replace openapi.yaml with your own backend's spec to document it the
same way.
Each function below corresponds 1:1 to an operationId in openapi.yaml.
// usage.js
import { getJSON, postJSON, putJSON, deleteJSON } from "https://cdn.jsdelivr.net/gh/crootjs/lib@0.0.15/api.min.js";
const API_URL = "https://api.example.com";
// GET /notes — listNotes
export function listNotes(onResult) {
getJSON(`${API_URL}/notes`, onResult);
}
// POST /notes — createNote
export function createNote(note, onResult) {
postJSON(`${API_URL}/notes`, note, onResult);
}
// PUT /notes/{id} — updateNote
export function updateNote(id, note, onResult) {
putJSON(`${API_URL}/notes/${id}`, note, onResult);
}
// DELETE /notes/{id} — deleteNote
export function removeNote(id, onResult) {
deleteJSON(`${API_URL}/notes/${id}`, {}, onResult);
}