Registry / web-framework / apipublisher

apipublisher

JSON →
library2.1.5jsnpmunverified

ApiPublisher is a Node.js framework for exposing asynchronous JavaScript APIs (returning Promises) over HTTP, enabling identical async function calls on client and server. Current version 2.1.5 requires Node >=10.0.0. It ships TypeScript types. Key differentiators: works seamlessly with Connect/Express, supports ES7 async/await via Nodent, offers browser RemoteApi with caching (including localStorage), and has been in production since 2013. Unlike generic RPC libraries, it preserves Promise semantics and supports nested APIs automatically.

npm install apipublisher
INSTALL
IMPORT
SIG · APIPUBLISHER
A
apipublisher
web-frameworkjavascriptv2.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ApiPublisher
import { ApiPublisher } from 'apipublisher'
const ApiPublisher = require('apipublisher')
ESM-only since v2.0.0 (package.json type: module). Default export not available; use named import.
RemoteApi
import { RemoteApi } from 'apipublisher'
TypeScript types provided. For browser usage, bundle with a bundler or use a CDN that supports ESM.
ServerApi
import { ServerApi } from 'apipublisher'
ServerApi is for Node-to-Node calls. It has a static method .load() which accepts a URL or Url object.

Exposes an async API over HTTP using Express. Note: 'api.handle' must be passed to app.use(), not the API object itself.

import { ApiPublisher } from 'apipublisher'; import express from 'express'; const app = express(); const myAPI = { greet: async (name) => `Hello, ${name}!`, add: async (a, b) => a + b }; const api = new ApiPublisher(myAPI); app.use('/api', api.handle); app.listen(3000, () => { console.log('Server listening on port 3000'); });
Debug
Known issues
breakingApiPublisher v1.1.x breaking change: you must pass `api.handle` to `app.use()`, not just `api`.
fix
Replace `app.use('/api', api)` with `app.use('/api', api.handle)`.
affects: >=1.1.0 <2.0.0
breakingESM-only since v2.0.0; CommonJS require() will fail.
fix
Use `import` syntax or upgrade to Node >=12 with --experimental-modules for older versions.
affects: >=2.0.0
deprecatedVersion 2.1.5 still uses Nodent internally; Nodent is unmaintained and may cause compatibility issues with modern Node.js.
fix
Consider migrating to a library that uses native async/await and standard Promises.
affects: 2.x
gotchaBrowser RemoteApi automatically provisions nested APIs under the same path; ensure your API object does not have overlapping property names with built-in methods like 'resolve' or 'then'.
fix
Avoid property names that conflict with Promise or Object prototypes.
affects: >=1.0.0
gotchaServerApi.load() accepts a URL object with options like 'agent', but the URL must be an instance of the Node URL class; plain strings are also accepted.
fix
Use `new URL('http://example.com/api')` if passing an object, or simply a string URL.
affects: >=1.2.0
Errors
Common errors & fixes
Cannot find module 'apipublisher'
Package not installed or wrong import path.
fix
Run `npm install apipublisher` and ensure you are using ESM import syntax (e.g., `import { ApiPublisher } from 'apipublisher'`).
TypeError: api is not a function
Passing the whole API object to app.use() instead of api.handle.
fix
Use `app.use('/path', api.handle)`.
SyntaxError: await is only valid in async function
Using 'await' outside an async function in non-ES7 code.
fix
Wrap the code in an async function: `async function main() { ... }` or use Promises with `.then()`.
ReferenceError: require is not defined
Using require() in an ESM context.
fix
Use `import { ... } from 'apipublisher'` or rename file to .cjs.
Upgrade
Version history
2.1.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
32
OpenAI (training)
1
Resources
apipublisher — npm install apipublisher · libregistry