{"id":20847862,"url":"https://github.com/jamesvillarrubia/feathers-rpc","last_synced_at":"2025-10-23T18:23:03.936Z","repository":{"id":69665900,"uuid":"604441692","full_name":"jamesvillarrubia/feathers-rpc","owner":"jamesvillarrubia","description":"Provides an FeathersJS (express and koa) middleware for translating Google-standardized RPC requests.","archived":false,"fork":false,"pushed_at":"2025-05-01T00:20:36.000Z","size":8142,"stargazers_count":5,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T01:36:45.156Z","etag":null,"topics":["expressjs","feathersjs","koa","rpc"],"latest_commit_sha":null,"homepage":"","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/jamesvillarrubia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-21T04:06:59.000Z","updated_at":"2025-02-24T17:36:54.000Z","dependencies_parsed_at":"2024-05-01T01:29:28.896Z","dependency_job_id":"64594ff6-7644-4591-ac9c-dc570af01f3a","html_url":"https://github.com/jamesvillarrubia/feathers-rpc","commit_stats":{"total_commits":47,"total_committers":2,"mean_commits":23.5,"dds":0.2978723404255319,"last_synced_commit":"f524b0702b011ec55bc7a10ed97e0ea8a6318c1a"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesvillarrubia%2Ffeathers-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesvillarrubia%2Ffeathers-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesvillarrubia%2Ffeathers-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesvillarrubia%2Ffeathers-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesvillarrubia","download_url":"https://codeload.github.com/jamesvillarrubia/feathers-rpc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253662656,"owners_count":21944113,"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":["expressjs","feathersjs","koa","rpc"],"created_at":"2024-11-18T02:23:29.125Z","updated_at":"2025-10-23T18:23:03.872Z","avatar_url":"https://github.com/jamesvillarrubia.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# feathers-rpc\n                    \n[![NPM](https://img.shields.io/npm/l/feathers-rpc)](https://github.com/jamesvillarrubia/feathers-rpc/blob/main/LICENSE) \n\n[![npm](https://img.shields.io/npm/v/feathers-rpc?label=latest)](https://www.npmjs.com/package/feathers-rpc)\n\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/jamesvillarrubia/feathers-rpc/npm-publish.yml?branch=main)\n\n[![Libraries.io dependency status for latest release](https://img.shields.io/librariesio/release/NPM/feathers-rpc)]()\n\n\u003c!-- [![Download Status](https://img.shields.io/npm/dm/feathers-rpc.svg)](https://www.npmjs.com/package/feathers-rpc) --\u003e\n\nThis library is a FeathersJS middleware to allow simple Remote Procedure Calls (RPCs) to interact with [Feathers Services](https://feathersjs.com/guides/basics/services.html) and [custom methods](https://feathersjs.com/api/services.html#custom-methods). \n\nTo function, this middleware takes an RPC verb from between the end of a path behind a colon (e.g. `/messages:callMySpecialMethod)` and then appends `callMySpecialMethod` as a parameter in the Feathers context as well as overwriting the `x-service-method` header.  This allows a custom method to be trigerred within the `/messages` service without requiring modification of headers directly, which can be disabled in some webhook and integration tools.\n\n\n## Installation\n```bash\nnpm install --save feathers-rpc\n```\n\nThen add the library to your middleware:\n\n```js \n//app.js\nconst parseRpcVerb = require('feathers-rpc');\n\n//...\n\napp.use(express.urlencoded({ extended: true }));\napp.use(parseRpcVerb());                          //\u003c--------\napp.configure(express.rest());\n```\n\n### `service(options)`\n__Options:__\n- `disableHeader` (**optional**, default: `false`) - Set to true to prevent the `x-service-method` header from being overwritten by the middleware.  The RPC verb can still get captured and used from the Feathers hook ctx object.\n- `allowedRpcVerbs` (**optional**. default: `any`) - Accepts a string or an array of strings.  Defaults to fully open, allowing any verb.  Setting to `[]` will disallow any verb. In order to use the `x-service-method` automatic call, the custom method of the service **must** be named exactly the same as the verb sent.\n\n\n## Example Service\n```javascript\n//app.js\n\nclass MessageService {\n  async find (params) { return { data: 'find', params }; }\n  async create (data, params) { return { data: 'create', params }; }\n  async callRpcMethod (data, params) { return { data: 'rpc', params }; }\n}\n\nconst app = feathers()\n  .configure(rest())\n  .use('/messages', new MessageService(), {\n    methods: ['find', 'create', 'callRpcMethod']\n  });\n```\n\nThen to hit this service you can follow the instructions [here](https://feathersjs.com/api/client/rest.html#custom-methods-1)\n\nThe following two curl requests are then basically equivalent:\n\n```bash \ncurl -H \"Content-Type: application/json\" \\\n  -H \"x-service-method: callRpcMethod\" \\\n  -X POST -d '{\"message\": \"Hello world\"}' \\ \n  http://localhost:3030/messages\n\ncurl -H \"Content-Type: application/json\" \\\n  -X POST -d '{\"message\": \"Hello world\"}' \\ \n  http://localhost:3030/messages:callRpcMethod\n```\n\n### Using Verbs with ID\n\nBecause the middleware doesn't know available routes or nesting, it cannot distinguish between `messages:verb` and `messages/1:verb`.  In order to pass a specific ID to your custom function, include it in the data `{ id: 1 }` or in the query `messages:verb?id=1`;  This will allow you to fetch that entity and still use the custom methods.\n\n### Extending an existing Service\n\nYou can easily add a custom method to any service and use the RPC middleware.  For example, if I was extending a Knex/SQL based service generated from the CLI, I would modify it like so:\n\n```javascript\nexport class MessagesService extends KnexService {\n   async callRpcMethod(data, params){\n      //... do fancy stuff\n    }\n}\n```\n\n## Compatability\nThis library is tested against REST APIs for Feathers v4 and v5.  This library also supports Koa on v5. Since the `x-service-method` header functionality does not exist in `v4`, the RPC verb can be extracted inside a hook context or params with the property `params.rpcVerb`.  You can then redirect to a separate function directly.\n\nAdditional testing and PRs are welcome.\n\n| feathers | v5                 | v4                 | v3              | \n|----------|--------------------|--------------------|-----------------|\n| express  | :white_check_mark: | :white_check_mark: | :grey_question: |  \n| koa      | :white_check_mark: | :grey_question:    | :grey_question: |  \n| primus   | :grey_question:    | :grey_question:    | :grey_question: |\n\n\n## Contributing\nPlease see https://github.com/jamesvillarrubia/feathers-rpc/blob/main/.github/contributing.md\n \n## Credit\nInspired by work by Ben Zelinski.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesvillarrubia%2Ffeathers-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesvillarrubia%2Ffeathers-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesvillarrubia%2Ffeathers-rpc/lists"}