{"id":15690595,"url":"https://github.com/linusu/raptor-rpc","last_synced_at":"2025-10-10T19:34:54.090Z","repository":{"id":16932012,"uuid":"19693768","full_name":"LinusU/raptor-rpc","owner":"LinusU","description":"Node.js library for creating RPC servers.","archived":false,"fork":false,"pushed_at":"2020-03-04T06:47:13.000Z","size":62,"stargazers_count":8,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T23:44:44.769Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LinusU.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-12T09:57:46.000Z","updated_at":"2023-06-12T22:19:11.000Z","dependencies_parsed_at":"2022-08-07T08:15:40.826Z","dependency_job_id":null,"html_url":"https://github.com/LinusU/raptor-rpc","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fraptor-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fraptor-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fraptor-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fraptor-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LinusU","download_url":"https://codeload.github.com/LinusU/raptor-rpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252973616,"owners_count":21834105,"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","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-10-03T18:12:31.847Z","updated_at":"2025-10-10T19:34:49.045Z","avatar_url":"https://github.com/LinusU.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Raptor RPC\n\nRaptor RPC is a transport-agnostic RPC server with middleware support and an\neasy to use api. It will allow you to have a server up and running in a matter\nof minutes, without limiting you to a specific transport.\n\nIt works out of the box with the standard transports provided by Node.js and\nalso with some popular frameworks.\n\n## Installation\n\n```sh\nnpm install --save raptor-rpc\n```\n\n## Usage\n\n```js\n// Raptor library\nconst Raptor = require('raptor-rpc')\n\n// Example libraries\nconst fetch = require('node-fetch')\nconst readJsonFile = require('read-json-file')\n\nconst app = new Raptor()\n\napp.use(function (req, next) {\n  console.log('Incoming request!')\n  return next()\n})\n\napp.method('ping', function (req) {\n  return 'pong'\n})\n\napp.method('get-package-name', function (req) {\n  return readJsonFile('package.json')\n    .then(pkg =\u003e pkg.name)\n})\n\napp.method('random-name', function (req) {\n  return fetch('http://uinames.com/api/')\n    .then(res =\u003e res.json())\n    .then(body =\u003e `${body.name} ${body.surname}`)\n})\n\napp.serve('http', 1337, function () {\n  console.log('Listening on http://localhost:1337/')\n})\n```\n\n## API\n\n### Raptor\n\n#### `.use(fn)`\n\nAdd middleware to the server.\n\n - `fn`: Middleware function with the signature `(req, next) =\u003e Promise`\n\nThe middleware function should return a promise of a response. Calling `next`\nwill return a promise of the next middleware or, if no other middleware exists,\nthe method handler.\n\n#### `.method(name, fn)`\n\nRegister a method with the server.\n\n - `name`: The method name\n - `fn`: Method handler with the signature `(req) =\u003e Promise`\n\nThe method handler should return a promise of what to respond with. It's also\nacceptable to return the value right away, since the handler is wrapped in a\n`.then` call. This also means that any errors thrown will be caught correctly.\n\n#### `.handle(...)`\n\nHandle a request, accepts a number of different parameters.\n\nRead more under `Transports`.\n\n#### `.attach(server)`\n\nAttaches Raptor to the server, accepts a number of different parameters.\n\nRead more under `Transports`.\n\n#### `.serve(type, port[, cb])`\n\nStarts a server and accepts connections.\n\n - `type`: Which transport to use (`dgram`, `http`, `net`)\n - `port`: Which port to listen to\n - `cb`: Function to be called when accepting connections\n\nReturns the server instance (`dgram.Socket`, `http.Server` or `net.Server`).\n\n### Request\n\n#### `.id`\n\nThe jsonrpc id of the request, can be `undefined`. This variable is read-only.\n\n#### `.method`\n\nThe method name of the request. This variable is read-only.\n\n#### `.params`\n\nThe params object as passed from the client. Can be `Array` or `Object`.\n\n#### `.param(key, defValue)`\n\nHelper function to get a parameter or a default value if it wasn't provided.\n\n - `key`: Key to fetch, can be `Number` or `String`\n - `defValue`: Value to return if `key` wasn't provided, is `undefined` if not specified.\n\n#### `.require(key, type)`\n\nHelper function to require the presence a parameter and optionally check it's\ntype. Will send an `Invalid params` error (-32602) back to the client, and stop\nexecution, if the parameter is not present. It also returns the value of the\nparameter.\n\n - `key`: Key to require, can be `Number` or `String`\n - `type`: If specified, also require the parameter to be of this type\n\nValid values for `type` is specified in the\n[JSON Schema: core definitions and terminology](http://json-schema.org/latest/json-schema-core.html#anchor8)\nand [RFC 4627](http://tools.ietf.org/html/rfc4627).\n\n\u003e This is implemented by throwing an Error if the key isn't present, or is of\n\u003e the wrong type.\n\n#### `.source`\n\nThe source of the connection, i.e. the stream that was piped to the connection.\n\n#### `.remote`\n\nInfo about the other end of the connection. Includes three keys:\n\n - `type`: Type of the transport (`unknown`, `dgram`, `http`, `net`)\n - `address`: Ip address of the remote\n - `port`: The remote port\n\n## Error handling\n\nIf you reject within a middleware or a method handler, that error will be sent\nback to the client. The description will be `err.toString()` and the code\n`err.rpcCode`. If `rpcCode` is undefined the code sent will be `0`.\n\nYou can also include additional data by providing `err.rpcData`. `rpcData` can\nbe of any type.\n\n## Transports\n\n### Express\n\n```js\nconst app = express()\nconst raptor = new Raptor()\n\napp.post('/api', raptor.handle)\napp.listen(1337)\n```\n\n### Dgram\n\n```js\nconst raptor = new Raptor()\nconst socket = dgram.createSocket('udp4')\n\nraptor.attach(socket);\nsocket.bind(1337);\n```\n\n### Net\n\n```js\nconst raptor = new Raptor()\nconst server = net.createServer({ allowHalfOpen: true })\n\nraptor.attach(server);\nserver.listen(1337);\n```\n\n### Http\n\n```js\nconst raptor = new Raptor()\nconst server = http.createServer()\n\nraptor.attach(server);\nserver.listen(1337);\n```\n\n## License\n\nCopyright \u0026copy; 2014 Linus Unnebäck \u003cbr\u003e\nLicensed under the MIT License (MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinusu%2Fraptor-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinusu%2Fraptor-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinusu%2Fraptor-rpc/lists"}