From 05e53d331194450e1ba1653c9c5591b87e2b05b5 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Wed, 11 Mar 2026 14:54:44 -0600 Subject: [PATCH] Add httpserver API docs --- docs/Plugin API/httpserver.md | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 docs/Plugin API/httpserver.md diff --git a/docs/Plugin API/httpserver.md b/docs/Plugin API/httpserver.md new file mode 100644 index 0000000..d84b378 --- /dev/null +++ b/docs/Plugin API/httpserver.md @@ -0,0 +1,49 @@ + + +## httpserver : object +Add features to PostalPoint's integrated LAN HTTP API server. + +**Kind**: global namespace + +* [httpserver](#httpserver) : object + * [.addEndpoint(id, onCall)](#httpserver.addEndpoint) + * [.getServerPort()](#httpserver.getServerPort) ⇒ number + * [.getClientKey()](#httpserver.getClientKey) ⇒ string + + + +### httpserver.addEndpoint(id, onCall) +Add a custom HTTP JSON POST endpoint to the LAN HTTP API server running inside +PostalPoint. Requests must be POSTed and contain a JSON body (or empty body, which will be converted to `null`). + +**Kind**: static method of [httpserver](#httpserver) + +| Param | Type | Description | +| --- | --- | --- | +| id | string | Endpoint ID. Used in URL, for example: `http://:7678/` | +| onCall | function | Async function to call when the endpoint is called, which returns the response. | + +**Example** +```js +global.apis.httpserver.addEndpoint("testendpoint", async function (request) { + if (request.abc == "123") { + // A non-string `body` is converted to JSON before the HTTP reply is sent. + return {body: {json: true, abc: 123}, httpcode: 200, contentType: "application/json"}; + } + // A string `body` is sent to the client as-is using whatever contentType you specify. + return {body: "abc", httpcode: 200, contentType: "text/plain"}; +}); +``` + + +### httpserver.getServerPort() ⇒ number +Get the local HTTP server's port number. + +**Kind**: static method of [httpserver](#httpserver) + + +### httpserver.getClientKey() ⇒ string +Get the local machine's HTTP client key it uses to authenticate with other +installations of PostalPoint on the LAN. + +**Kind**: static method of [httpserver](#httpserver)