Repository navigation
API
nself Admin provides a RESTful API for managing your development stack. All API endpoints are prefixed with /api/ and return JSON responses.
The API uses JWT-based authentication with sessions stored in the database.
POST /api/auth/loginRequest Body:
{
"password": "your-admin-password"
}Response:
{
"success": true,
"message": "Login successful"
}Cookies Set:
-
admin-token: JWT session token (httpOnly, secure in production)
POST /api/auth/logoutResponse:
{
"success": true,
"message": "Logout successful"
}GET /api/auth/sessionResponse:
{
"authenticated": true,
"userId": "admin"
}GET /api/setup/checkResponse:
{
"passwordSet": true,
"setupCompleted": true,
"projectInitialized": true,
"servicesBuilt": true,
"servicesRunning": true,
"projectPath": "/workspace"
}POST /api/setup/generate-envRequest Body:
{
"projectName": "my-project",
"baseDomain": "local.nself.org",
"databaseConfig": {
"version": "16-alpine",
"extensions": ["uuid-ossp"],
"customPassword": false
},
"authConfig": {
"providers": ["email", "github"],
"jwtSecret": "optional-custom-secret"
},
"storageConfig": {
"bucket": "nself"
},
"optionalServices": {
"redis": true,
"functions": false,
"dashboard": true
}
}Response:
{
"success": true,
"message": "Configuration file generated successfully",
"path": "/workspace/.env.local"
}GET /api/wizard/load-envResponse:
{
"success": true,
"config": {
"projectName": "my-project",
"environment": "development",
"domain": "local.nself.org",
"databaseName": "nself",
"backupSchedule": "0 2 * * *",
"optionalServices": {
"redis": true,
"mail": false,
"monitoring": false,
"mlflow": false,
"search": { "enabled": false, "provider": "auto" },
"admin": true
},
"customServices": [],
"frontendApps": []
},
"hasEnvFile": true
}POST /api/wizard/update-env-varRequest Body:
{
"key": "REDIS_ENABLED",
"value": "true",
"environment": "dev",
"remove": false
}Response:
{
"success": true,
"message": "Updated REDIS_ENABLED",
"key": "REDIS_ENABLED",
"value": "true"
}PUT /api/wizard/update-env-varRequest Body:
{
"variables": [
{ "key": "REDIS_ENABLED", "value": "true" },
{ "key": "MONITORING_ENABLED", "value": "false", "remove": true }
],
"environment": "dev"
}Response:
{
"success": true,
"message": "Updated 2 variables",
"count": 2
}POST /api/wizard/resetResponse:
{
"success": true,
"message": "Project reset successfully",
"details": {
"removedFiles": ["docker-compose.yml", ".env.dev"],
"message": "Project has been reset to initial state"
}
}POST /api/nselfRequest Body:
{
"command": "build",
"args": ["--verbose"],
"stream": true
}Response (Streaming):
data: {"type":"stdout","data":"Building project...\n"}
data: {"type":"stdout","data":"✓ Docker compose generated\n"}
data: {"type":"exit","code":0}
Supported Commands:
-
init: Initialize project -
build: Build Docker compose configuration -
start: Start all services -
stop: Stop all services -
reset: Reset project -
doctor: Run diagnostics -
status: Get service status -
logs: View service logs
GET /api/docker/statsResponse:
{
"containers": [
{
"id": "abc123",
"name": "postgres",
"status": "running",
"cpu": "2.5%",
"memory": "128 MB / 512 MB",
"network": "1.2 KB / 0.8 KB"
}
],
"images": 5,
"volumes": 3,
"networks": 2
}GET /api/docker/logs/:containerIdQuery Parameters:
-
tail: Number of lines to return (default: 100) -
since: Show logs since timestamp -
follow: Stream logs (boolean)
Response:
{
"logs": [
"2024-01-15 10:30:00 INFO: Server started",
"2024-01-15 10:30:01 INFO: Listening on port 5432"
]
}POST /api/docker/execRequest Body:
{
"containerId": "abc123",
"command": ["psql", "-U", "postgres", "-c", "SELECT version();"]
}Response:
{
"output": "PostgreSQL 16.0 on x86_64-pc-linux-gnu",
"exitCode": 0
}GET /api/monitoringResponse:
{
"healthy": true,
"services": [
{
"name": "postgres",
"status": "running",
"health": "healthy",
"uptime": "2h 15m",
"restarts": 0
}
],
"timestamp": "2024-01-15T10:30:00Z"
}GET /api/monitoring/metricsResponse:
{
"cpu": {
"usage": 15.5,
"cores": 4
},
"memory": {
"used": 2048,
"total": 8192,
"percentage": 25
},
"disk": {
"used": 10240,
"total": 51200,
"percentage": 20
},
"network": {
"rx": 1024000,
"tx": 512000
}
}POST /api/database/queryRequest Body:
{
"query": "SELECT * FROM users LIMIT 10",
"database": "nself"
}Response:
{
"success": true,
"rows": [{ "id": 1, "name": "John Doe", "email": "john@example.com" }],
"rowCount": 1,
"fields": ["id", "name", "email"]
}GET /api/database/schemaResponse:
{
"tables": [
{
"name": "users",
"columns": [
{ "name": "id", "type": "integer", "nullable": false },
{ "name": "name", "type": "varchar(255)", "nullable": true },
{ "name": "email", "type": "varchar(255)", "nullable": false }
]
}
]
}POST /api/database/backupRequest Body:
{
"database": "nself",
"format": "sql"
}Response:
{
"success": true,
"path": "/backups/nself_20240115_103000.sql",
"size": 1024000
}GET /api/services/templatesResponse:
{
"templates": [
{
"name": "express",
"category": "nodejs",
"description": "Express.js REST API",
"port": 4000
},
{
"name": "fastapi",
"category": "python",
"description": "FastAPI Python service",
"port": 4001
}
]
}POST /api/services/createRequest Body:
{
"name": "my-api",
"template": "express",
"port": 4000,
"environment": {
"NODE_ENV": "development",
"API_KEY": "secret"
}
}Response:
{
"success": true,
"service": {
"name": "my-api",
"port": 4000,
"status": "created"
}
}All API endpoints follow a consistent error response format:
{
"success": false,
"error": "Error message",
"details": "Additional error details",
"code": "ERROR_CODE"
}Common Error Codes:
-
AUTH_REQUIRED: Authentication required -
INVALID_PASSWORD: Invalid password -
NOT_FOUND: Resource not found -
VALIDATION_ERROR: Request validation failed -
DOCKER_ERROR: Docker operation failed -
CLI_ERROR: nself CLI command failed -
INTERNAL_ERROR: Internal server error
API endpoints are rate-limited to prevent abuse:
- Authentication endpoints: 5 requests per minute
- Query endpoints: 100 requests per minute
- Command execution: 10 requests per minute
For real-time updates, connect to the WebSocket endpoint:
const ws = new WebSocket('ws://localhost:3021/api/ws')
ws.on('message', (data) => {
const event = JSON.parse(data)
console.log('Event:', event.type, event.data)
})Event Types:
-
service.started: Service started -
service.stopped: Service stopped -
service.health: Health status changed -
build.progress: Build progress update -
logs.new: New log entry
import { NselfAdmin } from '@nself/admin-sdk'
const admin = new NselfAdmin({
url: 'http://localhost:3021',
password: 'your-password',
})
// Build project
await admin.build()
// Start services
await admin.start()
// Query database
const users = await admin.database.query('SELECT * FROM users')from nself_admin import NselfAdmin
admin = NselfAdmin(url="http://localhost:3021", password="your-password")
# Build project
admin.build()
# Start services
admin.start()
# Query database
users = admin.database.query("SELECT * FROM users")# Login
curl -X POST http://localhost:3021/api/auth/login \
-H "Content-Type: application/json" \
-d '{"password":"your-password"}' \
--cookie-jar cookies.txt
# Build project
curl -X POST http://localhost:3021/api/nself \
-H "Content-Type: application/json" \
-d '{"command":"build"}' \
--cookie cookies.txt
# Get status
curl http://localhost:3021/api/monitoring \
--cookie cookies.txtThe API currently uses v1 (implicit). Future versions will be explicitly versioned:
- Current:
/api/endpoint - Future:
/api/v2/endpoint
For API support and questions:
- GitHub Issues: https://github.com/acamarata/nself-admin/issues
- Documentation: https://github.com/acamarata/nself-admin/wiki
- Discord: https://discord.gg/nself
Version: 1.0.0 | Updated: 2026-10-19 11:40 UTC | GitHub