-
-
Notifications
You must be signed in to change notification settings - Fork 11
API Reference
REST API for Code Knowledge Backend (CKB) providing codebase comprehension capabilities.
# Start the server (default: localhost:8080)
./ckb serve
# Start on custom port
./ckb serve --port 8081
# Start on custom host
./ckb serve --host 0.0.0.0 --port 8080Root endpoint with API information and available endpoints.
curl http://localhost:8080/Simple liveness check for load balancers.
curl http://localhost:8080/healthResponse:
{
"status": "healthy",
"timestamp": "2024-12-16T12:00:00Z",
"version": "0.1.0"
}Readiness check that verifies backend availability.
curl http://localhost:8080/readyResponse:
{
"status": "ready",
"timestamp": "2024-12-16T12:00:00Z",
"backends": {
"scip": true,
"lsp": true,
"git": true
}
}Comprehensive system status including repository, backends, and cache.
curl http://localhost:8080/statusRun diagnostic checks on all system components.
curl http://localhost:8080/doctorResponse:
{
"status": "healthy",
"timestamp": "2024-12-16T12:00:00Z",
"checks": [
{"name": "config", "status": "pass", "message": "Configuration is valid"},
{"name": "scip", "status": "pass", "message": "SCIP backend available"}
],
"issues": [],
"summary": {
"total": 4,
"passed": 4,
"warnings": 0,
"failed": 0
}
}Get a fix script for detected issues.
curl -X POST http://localhost:8080/doctor/fixRetrieve detailed information about a symbol.
curl http://localhost:8080/symbol/my-symbol-idResponse:
{
"id": "my-symbol-id",
"name": "ExampleSymbol",
"kind": "function",
"location": {
"file": "example.go",
"line": 42
},
"module": "example"
}Search for symbols matching a query.
Query Parameters:
-
q(required) - Search query -
scope- Module ID to search within -
kinds- Comma-separated list of symbol kinds -
limit- Maximum results (default: 50) -
merge- Merge strategy: "prefer-first" or "union" -
repoStateMode- Repository state: "head" or "full" -
depth- Search depth (default: 1) -
includeExternal- Include external symbols (true/false) -
refresh- Force refresh cache (true/false)
curl "http://localhost:8080/search?q=myFunction&limit=10&kinds=function,method"Response:
{
"query": "myFunction",
"results": [],
"total": 0,
"hasMore": false,
"timestamp": "2024-12-16T12:00:00Z"
}Find all references to a symbol.
curl http://localhost:8080/refs/my-symbol-idResponse:
{
"symbolId": "my-symbol-id",
"references": [],
"total": 0,
"timestamp": "2024-12-16T12:00:00Z"
}Get an overview of the codebase architecture.
curl http://localhost:8080/architectureResponse:
{
"timestamp": "2024-12-16T12:00:00Z",
"modules": [],
"dependencies": [],
"metrics": {}
}Analyze the impact of changing a symbol.
curl http://localhost:8080/impact/my-symbol-idResponse:
{
"symbolId": "my-symbol-id",
"timestamp": "2024-12-16T12:00:00Z",
"impact": {},
"affected": [],
"risk": "low"
}Initiate cache warming for commonly accessed data.
curl -X POST http://localhost:8080/cache/warmResponse:
{
"status": "success",
"message": "Cache warming initiated",
"timestamp": "2024-12-16T12:00:00Z"
}Clear all cached data.
curl -X POST http://localhost:8080/cache/clearResponse:
{
"status": "success",
"message": "Cache cleared",
"timestamp": "2024-12-16T12:00:00Z"
}Get the OpenAPI 3.0 specification for the API.
curl http://localhost:8080/openapi.jsonAll errors return a consistent JSON structure:
{
"error": "Symbol not found",
"code": "SYMBOL_NOT_FOUND",
"details": null,
"suggestedFixes": [
{
"type": "run-command",
"command": "ckb doctor",
"safe": true,
"description": "Check system configuration"
}
],
"drilldowns": []
}| Status | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad Request - Invalid parameters |
| 404 | Not Found - Resource doesn't exist |
| 410 | Gone - Resource was deleted |
| 412 | Precondition Failed - Index stale |
| 413 | Payload Too Large - Budget exceeded |
| 422 | Unprocessable Entity - Validation error |
| 429 | Too Many Requests - Rate limited |
| 500 | Internal Server Error |
| 503 | Service Unavailable - Backend unavailable |
| 504 | Gateway Timeout |
-
X-Request-ID- Custom request ID (auto-generated if not provided) -
Content-Type: application/json- For POST requests
-
Content-Type: application/json- All responses are JSON -
X-Request-ID- Request ID for tracing -
Access-Control-Allow-Origin: *- CORS enabled for local dev
The API includes the following middleware (in order):
- CORS - Enables cross-origin requests
- Request ID - Generates unique request IDs
- Logging - Logs all requests and responses
- Recovery - Recovers from panics
# Start server
./ckb serve --port 8081
# Test all endpoints
curl http://localhost:8081/health | jq .
curl http://localhost:8081/status | jq .
curl "http://localhost:8081/search?q=test" | jq .
curl -X POST http://localhost:8081/cache/clear | jq .# Install jq if not already installed
brew install jq # macOS
apt-get install jq # Linux
# Pretty print responses
curl -s http://localhost:8080/status | jq .Server configuration via command-line flags:
| Flag | Default | Description |
|---|---|---|
--port |
8080 | Port to listen on |
--host |
localhost | Host to bind to |
The server supports graceful shutdown via interrupt signals:
# Press Ctrl+C to stop the server
# Or send SIGTERM
kill -TERM <pid>The server will:
- Stop accepting new connections
- Wait for active requests to complete (up to 10 seconds)
- Shut down cleanly
The API logs all requests and responses with:
- HTTP method and path
- Query parameters
- Status code
- Response time
- Request ID
Example log output:
2024-12-16T12:00:00Z [info] HTTP request | method=GET, path=/status, requestID=abc-123
2024-12-16T12:00:01Z [info] HTTP response | method=GET, path=/status, status=200, duration=100ms, requestID=abc-123
go build -o ckb ./cmd/ckb# Start with default settings
./ckb serve
# Start with custom port for development
./ckb serve --port 8081# Save to file
curl http://localhost:8080/status > status.json
# Show headers
curl -i http://localhost:8080/health
# Show request/response with verbose
curl -v http://localhost:8080/ready// Fetch status
fetch('http://localhost:8080/status')
.then(res => res.json())
.then(data => console.log(data));
// Search symbols
fetch('http://localhost:8080/search?q=myFunction&limit=10')
.then(res => res.json())
.then(data => console.log(data));# HTTPie
http GET localhost:8080/status
# wget
wget -qO- http://localhost:8080/health
# Python
python -c "import requests; print(requests.get('http://localhost:8080/status').json())"# Check if port is already in use
lsof -i :8080
# Use different port
./ckb serve --port 8081# Verify server is running
ps aux | grep ckb
# Check server logs for errors
./ckb serve 2>&1 | tee server.log# Validate JSON
curl http://localhost:8080/status | jq .
# Check response headers
curl -i http://localhost:8080/statusFor issues or questions:
- Check the OpenAPI spec:
GET /openapi.json - Review server logs
- Check the implementation documentation:
PHASE-4.2-IMPLEMENTATION.md