Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:APIJSON APIJSON Demo JSONRequest JS

From Leeroopedia
Knowledge Sources
Domains API_Design, HTTP_Client, Frontend
Last Updated 2026-10-14 00:00 GMT

Overview

Concrete tool for constructing and sending HTTP POST requests to APIJSON server endpoints provided by the APIJSON Demo frontend.

Description

The JSONRequest JavaScript module wraps XMLHttpRequest to send APIJSON-formatted JSON requests to the server's generic CRUD endpoints (/get, /post, /put, /delete, /head, /gets, /heads). It handles URL construction, JSON formatting, debug alerting, and response parsing. It defines base URL constants and the seven APIJSON method names.

Usage

Import this module when you need to send APIJSON requests from a browser-based JavaScript client to the APIJSON Demo server.

Code Reference

Source Location

Also duplicated at static/unit/apijson/JSONRequest.js (481 lines).

Signature

var URL_BASE = "http://localhost:8080";
var URL_GET = URL_BASE + "/get";
var URL_POST = URL_BASE + "/post";
var URL_PUT = URL_BASE + "/put";
var URL_DELETE = URL_BASE + "/delete";
var APIJSON_METHODS = ["get", "head", "gets", "heads", "post", "put", "delete"];

function request(url, json, notAlertRequest, onreadystatechange) { ... }
function get(json, notAlertRequest, onreadystatechange) { ... }
function post(json, notAlertRequest, onreadystatechange) { ... }
function put(json, notAlertRequest, onreadystatechange) { ... }
function del(json, notAlertRequest, onreadystatechange) { ... }
function format(json) { ... }

Import

var JSONRequest = require("./JSONRequest");
// or via script tag in browser

I/O Contract

Inputs

Name Type Required Description
url String Yes APIJSON endpoint URL
json JSONObject Yes APIJSON request body
notAlertRequest Boolean No Suppress debug alerts
onreadystatechange Function No XHR callback

Outputs

Name Type Description
request() returns JSONObject Parsed JSON response from server
get/post/put/del Function Convenience wrappers for request()

Usage Examples

Send a GET Request

var JSONRequest = require("./JSONRequest");

// Query User table
var request = {
  "User": {
    "id": 82001
  }
};

JSONRequest.get(request, true, function(response) {
  console.log(response);
  // { "code": 200, "User": { "id": 82001, "name": "Test", ... } }
});

Send a POST Request

// Insert a new user
var newRecord = {
  "User": {
    "name": "NewUser",
    "sex": 1
  }
};

JSONRequest.post(newRecord, true, function(response) {
  console.log(response);
  // { "code": 200, "User": { "id": 12345, ... } }
});

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment