`little-api` is a JavaScript library designed for creating simple JSON-over-HTTP/WS RPC servers and clients with minimal configuration. It acts as a lightweight wrapper around common web technologies like Express (for HTTP servers), XHRs (for HTTP clients), and WebSockets. The current stable version is 2.0.1. It provides a straightforward way to define server-side methods (both standard and WebSocket-specific) that are then exposed to a client-side API. A key differentiator is its emphasis on simplicity and low boilerplate, allowing developers to quickly set up RPC communication without diving into complex protocols. It strictly uses JSON as the transport format, meaning all arguments and return values must be JSON-serializable. Client-side usage relies on browser globals such as `XMLHttpRequest`, `WebSocket`, `btoa`, and `Promise`. The library does not specify a strict release cadence but provides a functional abstraction over underlying network primitives.
npm install little-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates setting up a `little-api` HTTP server with a few methods and then consuming those methods from a `little-api` client, including both asynchronous and synchronous calls.
Ensure all data passed to and from API methods adheres to the JSON specification (strings, numbers, booleans, null, arrays, plain objects).
Use `little-api/client` primarily in browser environments. If attempting to use in Node.js, ensure appropriate polyfills are available or consider a different RPC client solution.
Prefer the default asynchronous (Promise-based) client methods. Avoid `.sync` calls unless absolutely necessary for specific legacy contexts, and be aware of the performance implications.
Refactor your data structures to avoid circular references. If you need to pass complex objects, ensure they are simplified or transformed into JSON-serializable forms.
Ensure the client-side code runs in a browser environment or provide a suitable polyfill for `XMLHttpRequest` if running in a non-browser environment.
Change the port number for the `little-api` server or terminate the process currently using the desired port.