{"_id":"little-api","_rev":"3-6bd2550dd24ce760bd209d53ce5a22ab","name":"little-api","dist-tags":{"latest":"2.0.1"},"versions":{"1.0.0":{"name":"little-api","description":"A simple JSON-over-HTTP RPC server and client","keywords":["json","rest","api","server","client","rpc","http","express"],"version":"1.0.0","main":"index.js","license":"MIT","dependencies":{"body-parser":"^1.18.3","cors":"^2.8.5","debug":"^4.1.0","express":"^4.16.4"},"devDependencies":{"concurrently":"^4.1.0","html-webpack-plugin":"^3.2.0","nodemon":"^1.18.8","webpack":"^4.27.1","webpack-cli":"^3.1.2","webpack-dev-server":"^3.1.10"},"scripts":{"client":"webpack-dev-server --config test/webpack.config.js","server":"nodemon test/server.js","start":"concurrently 'yarn client' 'yarn server'"},"gitHead":"cbc262c2cb630617977d34c8aaa92481a357b3a1","_id":"little-api@1.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"suchipi","email":"me@suchipi.com"},"dist":{"integrity":"sha512-Tv5IQVWrjNfw/8Unl6/cjqp2mp9QbI8w2zlM3hit4EDV5TUjpYqnb0lJyVLn+rLgoF5IYZIQoDpjgF3w/565lQ==","shasum":"b56d1a0db07bfef5be034600f005810d283fd7e2","tarball":"https://registry.npmjs.org/little-api/-/little-api-1.0.0.tgz","fileCount":7,"unpackedSize":190502,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcEV8rCRA9TVsSAnZWagAAnbgP/iKKqtBzwwaYxJpsmjcJ\nV+NGBUvy2S50X9deH4i8XaKcQxmfVYk3iKnYUO7ZnBNXBokkQCPs9fbtTdVd\n0nQTdoiVpWkTxktPmSwLxQm6Bedtd6PHbBbW/7qZF3Zp3mh8Rk4QQgUbR4Ou\n/0e6x1wnGTVUuA/RJXIdgSMSJeotcpKvONNa204xzrzEeebN3Yy7TARj7LSA\nLfq77B2eRciqkpgtVpGI5jp+Pz91pAxh+Dy2BqR9fRTVzlEb9F7MBb2CBlvw\nnOb+ELvSwmGrj29pt3fWhoaRGotPNnlfNJOfVDWWF5mBmxXyriQryrRGZRgO\nqcoVuveUfdSI2NKoVu4AQOVkagPgchcPkZCb2uoyX0jk7RG8Gz3QANqsTgu3\nenOB+g/EDRSNxGJleHZ8K1W0jIVLrGCCbJXINN2nURZYtfP8QvdI7N7gNXsj\nGS3X+91GeYTncCSHz4QI1aB6WNBv+7yHtvJwSgatt/zApeRpZO5cGxMZMdya\nKfYcPJIISVSbSSIScsTZJzWhXqYARqAVU5hzqkxTBQtATecFF0XKy9Ui1I34\nuTmY92HwZKxXgrrD/Jl85BrcpwTeCUXmS9QAIzqIb6ha9T0uCzTQwr/+LCYT\nwE5RSy8V1PlLmmRaSRGazdx98VJEm5Sw2BOp2br+AejTc+7gkhE8xH4EOFkG\nfkq+\r\n=ht+y\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG1mrIcKzl1R1LcjP+nbvnnhPW+0WoupqU9ENhA9g6YvAiEA+NRghLG0FxP/UiiB63iSUcvays0kavYl4fwxjDG2Mg4="}]},"maintainers":[{"name":"suchipi","email":"me@suchipi.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/little-api_1.0.0_1544642346881_0.7911464057125082"},"_hasShrinkwrap":false},"2.0.0":{"name":"little-api","description":"A simple JSON-over-HTTP/WS RPC server and client","keywords":["json","rest","api","server","client","rpc","http","express","websocket","socket","stream"],"version":"2.0.0","main":"index.js","license":"MIT","dependencies":{"body-parser":"^1.18.3","cors":"^2.8.5","debug":"^4.1.0","express":"^4.16.4","ws":"^6.1.2"},"devDependencies":{"concurrently":"^4.1.0","html-webpack-plugin":"^3.2.0","nodemon":"^1.18.8","webpack":"^4.27.1","webpack-cli":"^3.1.2","webpack-dev-server":"^3.1.10"},"scripts":{"client":"webpack-dev-server --config test/webpack.config.js","server":"nodemon test/server.js","start":"concurrently 'yarn client' 'yarn server'"},"gitHead":"895e58a40c2860e25d668c8fa3af1dadb806fa09","_id":"little-api@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"suchipi","email":"me@suchipi.com"},"dist":{"integrity":"sha512-zbCkNNvp0Eteo9Fk3HE2ibyzmakw2sO4ZVdnNttA+mTgw3lZwpTeOoojlTDWTK76SmKZJxJ1yRBQqTxvN5lWjQ==","shasum":"c1a6e1ffe89650491cab3e1983b17982f8a64c6f","tarball":"https://registry.npmjs.org/little-api/-/little-api-2.0.0.tgz","fileCount":7,"unpackedSize":195475,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcEsDuCRA9TVsSAnZWagAAzTIP/1oHaRzMpsMha4sNK/OA\nlo+y/T9HqtrX1R/3mzSL4DBxMO+AvZ9AuUuGeugjRyZ8o+jhSRSunM1dOo8d\n9Fly0lM06NQSWg1GCrQeBqV/Al5+Q/gb2jt4v5/f1tq6kE0AAE5dIr61qoiF\nD9Okz1/mDA/IJW3/ZyZGsaE64dElbGlghids8n+KlTZjvxBdB3i1WvqQZJ/2\ng3E3wCiLsGub6Nm+YfNd5BzHlfqNUEEVZaGcVq0YH7O/j2Omu/Jb4mH7s4tD\n4dmAqslkIjOvLtCsBnzpdqlolZp2RpOWBICnEdaRTCn9CP1wjAMJQJ7QpBJK\nwocdR1FDbpVLwtC3YgaIKvPpxw69I+G1dvoHwA3eTetkFqSZt1got5aECar1\nF2GStbcAEK4z3vRxorHvpOSmD9SQh/U6ITuMfgmcn+LpTbiThwH2NSVGUGDN\nhe327P8Slx15Gb+iOSUOVCwEvpeTkyKsGSytvEJga6Vn1h6TQMYfmmxTJJCV\n+y+Swbt0rU8HoFlgGe5ITFwU0IWbsgEK8adtLhmsDHqbU/K7xxJBQykO1P7O\nDKJpUbXH5NBz9K0MkQmexPj2M/Pf2voyHXd2v8QjOAURkXRyP3XFP//gk3Kz\nf8LvGVczKQscnJBA+RNnFQfwXyjX7eh87T1/67JfltYcY9S7WK4JobBB02RD\nvA1H\r\n=JcVX\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD7R4NuOXH0Y/aeAlL34QyUN8627dshFC5C2xjkZJGUTgIgEfZqihzeFqRfpsru/BGMzLPYKu7toaWVq13S9UdpEXo="}]},"maintainers":[{"name":"suchipi","email":"me@suchipi.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/little-api_2.0.0_1544732909566_0.7553963643134709"},"_hasShrinkwrap":false},"2.0.1":{"name":"little-api","description":"A simple JSON-over-HTTP/WS RPC server and client","keywords":["json","rest","api","server","client","rpc","http","express","websocket","socket","stream"],"version":"2.0.1","main":"index.js","license":"MIT","dependencies":{"body-parser":"^1.18.3","cors":"^2.8.5","debug":"^4.1.0","express":"^4.16.4","ws":"^6.1.2"},"devDependencies":{"concurrently":"^4.1.0","html-webpack-plugin":"^3.2.0","nodemon":"^1.18.8","webpack":"^4.27.1","webpack-cli":"^3.1.2","webpack-dev-server":"^3.1.10"},"scripts":{"client":"webpack-dev-server --config test/webpack.config.js","server":"nodemon test/server.js","start":"concurrently 'yarn client' 'yarn server'"},"gitHead":"165509365cb1b09ade6c7b48ba6f538ee681bea9","_id":"little-api@2.0.1","_nodeVersion":"14.15.5","_npmVersion":"6.14.11","dist":{"integrity":"sha512-au2Oh72jCfPyDKOigCbIpAuibf7hMRQzhb5y2N5x5PYFRexhcpIhs13Qjr7an1Pg6g8YZxO0vA+r/8kxW1LM6w==","shasum":"e8da6456477c61ec91335c8ff9a1c35b70ac5f03","tarball":"https://registry.npmjs.org/little-api/-/little-api-2.0.1.tgz","fileCount":6,"unpackedSize":13892,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgzC0ICRA9TVsSAnZWagAAqfEP/An0xZ3kBOHQebDEer/H\n/jZDPmj/dfq9dKgpSf4ShePAuaGzQPNcbQYWG63mjwbVNHZJxPk51dXey2Mz\nLZsAW87BbTSMF+qLcE8/uKBGz/QaZd0uWgpBSorzxYnPqNJ1xhswJdtzLJlz\nNWwAr/Fv3UgrhQaqQViwXeVk7aRY2e/ICBV2m7BoBJAjOKaP1cCkVT6VQKff\n+3cmLECJTWIczfJR/49G8h7deOYcqiTqHgAJJtM7Sjae2ZE6I8rDlcS50+Mk\nCfeSTvJFuERCBiiVf2Bx0jmoPB47hFrONaIfZxKRyaYgbXGTonSradVyLZrU\nU4jFtdpqPjaayYL1/Vm8PVHPkVbytMhI4QdtGTdSbne5QkHs9I1l+tPIPVBv\noZ8NGuQjpqvscTMMhaCXEvxI/WPNpvNIdBAUZbYW/7AJ0d1k5OuIYFAwh/8K\neZrra/Ul5Wv7IxkrbP9BDdwVnnEvvin6aYmUdr+zydt6Mf26lFoXGLuWRQCB\n48/ttBf+Jb0cG4NKFAIQummOLM9R83yYM+PBOsFKKCE8SFiNFW+LI7rTlb9i\nKKRujSJUH7LtthnEOgfbxNCf/8GX7Ne0IWyWYjyj/nA5nX4xlcBcEn7Qol9d\n09mXwzDnQEnMfFj0Kjky2ipIzgCB7PcjmZT+9fLvCb0JhCPhGIXvGD+ULgd9\njATx\r\n=JIe8\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCtCJto0GSf/ApUs3OQZlYLfMbLHXdDsAB0CoCo1bBojgIhALoL81CXyxGay2wdXocFRoWZuBCn9HLU0h89h01m1s44"}]},"_npmUser":{"name":"suchipi","email":"me@suchipi.com"},"directories":{},"maintainers":[{"name":"suchipi","email":"me@suchipi.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/little-api_2.0.1_1623993607689_0.7501373964163014"},"_hasShrinkwrap":false}},"time":{"created":"2018-12-12T19:19:06.881Z","1.0.0":"2018-12-12T19:19:07.027Z","modified":"2022-05-08T04:47:11.472Z","2.0.0":"2018-12-13T20:28:29.688Z","2.0.1":"2021-06-18T05:20:07.845Z"},"maintainers":[{"name":"suchipi","email":"me@suchipi.com"}],"description":"A simple JSON-over-HTTP/WS RPC server and client","keywords":["json","rest","api","server","client","rpc","http","express","websocket","socket","stream"],"license":"MIT","readme":"# little-api\n\n`little-api` is a wrapper around express, XHRs, and WebSockets that gives you a nice JSON-over-HTTP/WS RPC server and client with little configuration.\n\n## Installation\n\n```\nnpm install --save little-api\n```\n\n## HTTP Usage\n\nOn the server:\n\n```js\nconst createServer = require(\"little-api/server\");\n\nconst server = createServer({\n  methods: {\n    // Fill this object with functions that do whatever you want.\n    // They will be wrapped with an HTTP API that makes them available to clients.\n    // These functions can return a JSON-serializable value or a Promise that resolves to one.\n    uppercase(...words) {\n      return words.map((word) => word.toUpperCase());\n    },\n    uppercaseAsync(...words) {\n      return Promise.resolve(words.map((word) => word.toUpperCase()));\n    },\n  },\n});\n\n// `server` is a node net.Server.\nserver.listen(8080, () => {\n  console.log(\"Server is listening on port 8080\");\n});\n```\n\nOn the client:\n\n```js\nconst createClient = require(\"little-api/client\");\n\nconst api = createClient({\n  url: \"http://localhost:8080\",\n  methods: [\"uppercase\", \"uppercaseAsync\"],\n});\n\n// api is an object with properties on it for each method:\nconsole.log(api);\n// {\n//   uppercase: function uppercase() { ... },\n//   uppercaseAsync: function uppercase() { ... }\n// }\n\n// calling each method passes the args to the server, calls the cooresponding method serverside, and returns a Promise with the result:\napi.uppercase(\"hello\", \"world\").then((results) => {\n  console.log(results); // [\"HELLO\", \"WORLD\"]\n});\n\n// You can use the `.sync` property on each function to use Synchronous XHRs:\nconst results = api.uppercase.sync(\"hello\", \"world\");\nconsole.log(results); // [\"HELLO\", \"WORLD\"]\n```\n\n## WebSocket Usage\n\nYou can also use little-api for your websocket server.\n\nOn the server:\n\n```js\nconst createServer = require(\"little-api/server\");\n\nconst server = createServer({\n  // Use the socketMethods key instead of methods. You can use both socketMethods and methods together if you want to.\n  socketMethods: {\n    // Fill this object with functions that handle incoming socket connections.\n    // Each will receive a socket object and any args that were passed to the function clientside.\n    fancyEcho(socket, repeatTimes, uppercase = false) {\n      socket.on(\"message\", (message) => {\n        message = message.repeat(repeatTimes);\n        if (uppercase) {\n          message = message.toUpperCase();\n        }\n        socket.send(message);\n      });\n    },\n  },\n});\n\n// `server` works the same as usual.\nserver.listen(8080, () => {\n  console.log(\"Server is listening on port 8080\");\n});\n```\n\nOn the client:\n\n```js\nconst createClient = require(\"little-api/client\");\n\nconst api = createClient({\n  url: \"http://localhost:8080\",\n  socketMethods: [\"fancyEcho\"],\n});\n\n// api has properties for each socket method on it in addition to any normal methods you specify:\nconsole.log(api);\n// {\n//   fancyEcho: function fancyEcho() { ... }\n// }\n\n// calling a function associated with a socket method will return a websocket instance:\nconst websocket = api.fancyEcho(/* repeatTimes */ 3, /* uppercase */ true);\nwebsocket.addEventListener(\"message\", (event) => {\n  console.log(event.data);\n});\nwebsocket.send(\"hello\"); // logs HELLOHELLOHELLO\nwebsocket.send(\"world\"); // logs WORLDWORLDWORLD\n```\n\n## Notes/limitations\n\n- JSON is used as the transport format, so the arguments passed into client functions must be JSON-serializable, and the return/resolve values from the server must be JSON-serializable.\n- The client relies on the globals `XMLHttpRequest`, `WebSocket`, `btoa`, and `Promise`.\n\n## API\n\n### `createServer(serverConfig: Object) => net.Server`\n\nThe `createServer` function comes from the module `\"little-api/server\"`. It returns a node net.Server that you can call `listen` on.\n\n`serverConfig` is an Object that may have any of these keys:\n\n- `methods` - An Object of functions that should be exposed as API methods to the client.\n- `socketMethods` - An Object of functions that should be run when a websocket client connects. Each receives a `socket` object and the args that were passed clientside.\n- `requestSizeLimit` - The maximum permitted request size. Defaults to `\"1GB\"`.\n- `noCors` - Set to true disable CORS. It's enabled by default.\n- `corsOptions` - Options to pass to the [cors package](https://www.npmjs.com/package/cors).\n- `withApp` - A function that, if present, will be called with the express app right before it is passed to `http.createServer`. You can use this to add your own method handlers or middleware. Note that for the functions defined in `methods` to work, the `POST /` handler should be left alone.\n\n### `createClient(clientConfig: Object) => Object`\n\nThe `createClient` function comes from the module `\"little-api/client\"`. It returns an Object whose entries are functions cooresponding to the methods on the server. Each non-socket-method function has a property called `sync` which is a function that use a Synchronous XHR instead of an async one.\n\n`clientConfig` is an Object that must have at least this key:\n\n- `url` - The URL to the server, eg. `\"http://localhost:8080\"`\n\nAnd may optionally also have these keys:\n\n- `methods` - An Array of strings, containing the names of all the methods available on the server.\n- `socketMethods` - An Array of strings, containing the names of all the socket methods available on the server.\n- `timeout` - The timeout in milliseconds to set on the XHRs used to communicate with the server. Defaults to 30 seconds; set to `0` for no timeout.\n\n## License\n\nMIT\n","readmeFilename":"README.md"}