Skip to main content

Introduction

The KnowledgeCheckr API provides a comprehensive set of endpoints for creating, managing, and interacting with knowledge checks, questions, and examinations. Built with Next.js and TypeScript, the API uses Zod for robust schema validation and Drizzle ORM for database operations.

Base URL

All API requests are made to:
https://your-domain.com/api

Authentication

The KnowledgeCheckr API uses Better Auth for authentication. Most endpoints require authentication using session-based authentication.

Authentication Methods

Login

Authenticate users with email and password:
const credentials = {
  email: "[email protected]",
  password: "securepassword123",
  callbackURL: "/dashboard" // optional, defaults to '/'
}
Requirements:
  • Email must be a valid email address
  • Password must be at least 8 characters long
  • Callback URL is optional and defaults to /

Signup

Register new users:
const signupData = {
  name: "John Doe",
  email: "[email protected]",
  password: "securepassword123",
  callbackURL: "/dashboard" // optional
}
Requirements:
  • Name must be at least 1 character long
  • Email must be a valid email address
  • Password must be at least 8 characters long

Protected Endpoints

Most API endpoints require authentication and will return a 401 Unauthorized error if accessed without valid credentials. The authentication is handled server-side using the requireAuthentication() function.
const { user } = await requireAuthentication()

Request Format

All POST requests must include a Content-Type: application/json header and provide data in JSON format.
fetch('/api/insert/knowledgeCheck', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(knowledgeCheckData)
})

Response Format

API responses are returned in JSON format.

Success Response

{
  "success": true,
  "data": { ... }
}

Error Response

{
  "message": "Error description",
  "errors": [
    {
      "path": ["fieldName"],
      "message": "Validation error message"
    }
  ],
  "timestamp": 1234567890
}

Validation

All API endpoints use Zod schemas for request validation. Invalid requests will return a 400 Bad Request response with detailed validation errors.

Common Validation Errors

  • Invalid UUID: IDs must be valid UUIDs
  • Required fields: Missing required fields will be rejected
  • Type mismatch: Fields must match expected types
  • Range constraints: Numeric values must fall within specified ranges
  • Date validation: Dates must be valid and follow constraints (e.g., closeDate cannot be before openDate)

Rate Limiting

Rate limiting policies should be configured based on your deployment environment.

Error Codes

Status CodeDescription
200Success
400Bad Request - Invalid input or validation error
401Unauthorized - Authentication required
403Forbidden - Insufficient permissions
404Not Found - Resource does not exist
500Internal Server Error

API Versioning

The current API version can be checked at:
GET /api/version

Next Steps

Schemas

Learn about Zod validation schemas

Database Operations

Explore CRUD operations

Build docs developers (and LLMs) love