Skip to content

REST API Example

A REST API example with CRUD operations, authenticated endpoints, and multiple route patterns.

Source: examples/rest-api/

  • Authenticated endpoints — scopes enforce access control
  • Public + private routes — health check is public, CRUD requires auth
  • Dynamic segments[id] in route paths
  • Multiple HTTP methods — GET, POST, PUT, DELETE
  • Auto status codes — POST → 201, DELETE → 204
RouteAuthDescription
GET /healthPublicHealth check
GET /taskstasks.readList tasks
POST /taskstasks.writeCreate task (201)
GET /tasks/{id}tasks.readGet task by ID
PUT /tasks/{id}tasks.writeUpdate task
DELETE /tasks/{id}tasks.writeDelete task (204)
Terminal window
cd examples/rest-api
npm install
vk dev
Terminal window
# Public
curl http://localhost:3000/health
# Authenticated (requires Bearer token with tasks.read scope)
curl -H "Authorization: Bearer <token>" http://localhost:3000/tasks
# Create
curl -X POST -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"title": "New task"}' \
http://localhost:3000/tasks