Skip to content

Latest commit

 

History

73 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TestAPI

Browser-based HTTP/1.1 API emulator and response editor.
Configure arbitrary status codes, response headers and bodies, and inspect incoming request logs from the browser.

Requirements

Optional

websys is required only when console authentication is enabled in appconfig.py. It is not required by default.

Deploy

Edit the shebang in index.cgi, console/index.cgi and console/api.cgi to the Python path of your web server.
Deploy the files to the server as below:

/
|
+- testapi/
|  |
|  +- apiimpl.py [644]
|  +- appcommon.py [644]
|  +- appconfig.py [644]
|  +- applogger.py [644]
|  +- index.cgi [755]
|  +- test.html [644]
|  |
|  +- console/
|     |
|     +- api.cgi [755]
|     +- apiimpl.py [644]
|     +- index.cgi [755]
|     +- main.js [644]
|     +- screen.py [644]
|     +- style.css [644]
|
+- libs/
   |
   +- util.js
   +- util.py

When console authentication is enabled, deploy websys at /websys/.

The web server process must be able to write the response data and log files used by TestAPI.
Create the runtime paths as needed and grant write permission to the web server process:

testapi/_data_.txt
testapi/logs/testapi.log
testapi/logs/details/

Console authentication is configured in appconfig.py:

console_auth_required = False
console_app_permission_name = 'testapi'

Set console_auth_required to True when websys authentication is used.

Usage

Open the console:

http(s)://SERVER/testapi/console/

Edit the HTTP response headers and body, then click Apply.
The configured response is served at:

http(s)://SERVER/testapi/

For example, the response data can be configured as:

HTTP/1.1 200 OK
Date: Sat, 19 Sep 2026 12:20:28 GMT
Content-Type: application/json
Content-Length: 27

{"message": "Hello, World!"}

The console provides quick templates for common HTTP status codes such as 200, 301, 400, 401, 403, 404, 500 and 503.
Other status codes can be selected from the status list or entered manually. Auto Apply immediately saves a selected template, Set Date updates the Date header, and Revert reloads the currently saved response.

Content-Length is updated automatically when the response body is edited.

testapi1

Built-in APIs

The api query parameter can be used to call several built-in test endpoints instead of the configured response.

http(s)://SERVER/testapi/?api=hello
http(s)://SERVER/testapi/?api=hello&name=Alice
http(s)://SERVER/testapi/?api=ip
http(s)://SERVER/testapi/?api=host
http(s)://SERVER/testapi/?api=status&code=404

Examples:

GET /testapi/?api=hello
{"message": "Hello!"}
GET /testapi/?api=hello&name=Alice
{"message": "Hello, Alice!"}
GET /testapi/?api=status&code=404
HTTP/1.1 404 Not Found

Access Logs

Requests handled by the configurable API are recorded in the console.
The log shows the request time, method, response status, remote IP address, User-Agent and response size.

Click a request log entry to inspect detailed request and response information, including headers and body.
The logger keeps up to 20 recent entries and detailed logs by default.

License

MIT License

About

Test API with API emulator that returns mock responses

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages