Implementation:APIJSON APIJSON Demo Server JS
| Knowledge Sources | |
|---|---|
| Domains | Testing, HTTP_Server, Node_JS |
| Last Updated | 2026-10-14 00:00 GMT |
Overview
Concrete tool for running a Koa HTTP server that triggers and monitors APIJSON regression tests, comparing responses against standards.
Description
The Server.js module is a Koa-based HTTP server (port 3000) that exposes endpoints for automated APIJSON regression testing: /test/start (launches App.autoTest), /test/status (returns progress and report link), /test/compare (compares a response against a standard via JSONResponse.compareResponse), and /test/ml (ML-mode comparison). It handles CORS, tracks progress across accounts, test cases, deep tests, and random tests.
Usage
Run this Node.js server when you need to execute APIJSON regression tests from a headless environment and query test progress via HTTP.
Code Reference
Source Location
- Repository: APIJSON_APIJSON_Demo
- File: APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/unit/js/server.js
- Lines: 1-205
Signature
const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const {getRequestFromURL, App} = require('./main');
const JSONResponse = require('../apijson/JSONResponse');
// Endpoints:
// /test/start - Launch auto testing
// /test/status - Query progress
// /test/compare - Compare response vs standard
// /test/ml - ML-mode comparison
app.listen(PORT); // PORT = 3000
Import
node server.js
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| key | String | No | Test query parameter for elevated test counts |
| response | JSONObject | No | Actual response for comparison |
| standard | JSONObject | No | Expected standard for comparison |
Outputs
| Name | Type | Description |
|---|---|---|
| /test/status returns | JSONObject | Progress, message, reportId, link |
| /test/compare returns | JSONObject | Diff comparison result |
Usage Examples
Start Regression Test
# Start auto testing
curl http://localhost:3000/test/start
# Check status
curl http://localhost:3000/test/status
# {"code":200,"msg":"Auto testing...","progress":0.5,...}