{"id":21436946,"url":"https://github.com/axfab/srpc","last_synced_at":"2025-10-12T09:15:07.018Z","repository":{"id":34496471,"uuid":"38436848","full_name":"AxFab/srpc","owner":"AxFab","description":"An easy to use RPC implementation using json-rpc specification.","archived":false,"fork":false,"pushed_at":"2015-07-02T15:09:22.000Z","size":120,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-27T11:28:08.581Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AxFab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-02T14:17:36.000Z","updated_at":"2019-05-24T11:53:11.000Z","dependencies_parsed_at":"2022-09-05T19:20:34.421Z","dependency_job_id":null,"html_url":"https://github.com/AxFab/srpc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AxFab/srpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxFab%2Fsrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxFab%2Fsrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxFab%2Fsrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxFab%2Fsrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AxFab","download_url":"https://codeload.github.com/AxFab/srpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AxFab%2Fsrpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010963,"owners_count":26084837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-23T00:16:57.071Z","updated_at":"2025-10-12T09:15:07.004Z","avatar_url":"https://github.com/AxFab.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SRPC\n\n  [![NPM Version][npm-image]][npm-url]\n  [![NPM Downloads][downloads-image]][downloads-url]\n  [![Travis Build][travis-image]][travis-url]\n\n\nAn easy to use RPC implementation using json-rpc specification.\n\n    npm install srpc\n\n### Getting Started\n\n#### Create a RPC service\nSRPC allow to share method across network using HTTP request. We first have to defined the new service that will be shared. Any object can be declared as a service, all functions contained by the object will be exposed as a remote procedure. Note that the this reference will be overwritten so prefer a static API.\n\n```js\n// Create the API\nvar MyService = {\n\n  // function `hello' is accessible via RPC\n  hello: function (name, callback) {\n    callback(null, 'Hello ' + name + '!')\n  }\n}\n```\nA remote procedure must take a _callback_ as its last argument. This function will be called with an error object as first argument and a response object as second.\n\n#### Create a server\n\nTo create a server, you will need the __http__ package and to use the function `listener()`:\n```js\nvar srv = http.createServer (srpc.listener(MyService));\nsrv.listen(8080);\n```\nYou can replace easily the _http_ server by an _https_ one. That is your server is ready.\nTo go further, note that `srpc.listener()` have the  prototype of a __requestListener__. As such you can use with many router library, like express to provide several services.\n```js\nvar app = require('express')(),\n    srpc = require('srpc');\n// ...\napp.use('/users', srpc.listener(UserService));\napp.use('/account', srpc.listener(AccountService));\napp.listen(80);\n```\n \n\n\u003e__Note__: The `srpc.listener()` function ignore which path or http-verbs is used for the moment (POST is adviced). I'm working to accept web-socket to allow keep-alive communication.\n\n#### Open a client connection\nTo start a client, you will need to use the `srpc.connect()` function which give you back an object similar to the service defined on the server.\n\n```js\n// Create the client connection\nvar url = 'http://localhost:8080/'\n\nsrpc.connect(url, function (err, rpc) {\n  if (err) return console.error(err)\n\n  // Asynchronous call to the function `hello'\n  rpc.hello ('World', function (err, res) {\n    if (err) return console.error(err)\n    console.log (res)\n  })\n})\n```\nthe object provided contains every defined remote-procedure and two other members:\n\n * An object name `#wsp` which define the remote API:\n `{ \"methods\": { \"hello\": \"params\": [ \"name\", \"callback\"] } } }`\n * A methods named `invoke(methods, params, callback)` which allow to call any remote procedure.\n\n\n\u003e _Look at the file `sample.js` to test the command given here._\n\n\n\n### License\n\n\nCopyright (c) 2015, Fabien Bavent\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\n3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n\n[npm-image]: https://img.shields.io/npm/v/srpc.svg\n[npm-url]: https://npmjs.org/package/srpc\n[downloads-image]: https://img.shields.io/npm/dm/srpc.svg\n[downloads-url]: https://npmjs.org/package/srpc\n[travis-image]: https://img.shields.io/travis/AxFab/srpc.svg\n[travis-url]: https://travis-ci.org/AxFab/srpc\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxfab%2Fsrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faxfab%2Fsrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faxfab%2Fsrpc/lists"}