{"id":13879000,"url":"https://github.com/cloud66-oss/unrestful","last_synced_at":"2025-04-10T13:31:36.237Z","repository":{"id":59158745,"uuid":"191610494","full_name":"cloud66-oss/unrestful","owner":"cloud66-oss","description":"Simple, lightweight and mountable RPC for Rails","archived":false,"fork":false,"pushed_at":"2019-08-07T12:20:18.000Z","size":95,"stargazers_count":17,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T05:15:48.205Z","etag":null,"topics":["rails","rest","rpc"],"latest_commit_sha":null,"homepage":"https://www.cloud66.com","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloud66-oss.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":"2019-06-12T16:48:12.000Z","updated_at":"2024-05-25T14:49:42.000Z","dependencies_parsed_at":"2022-09-13T20:11:20.830Z","dependency_job_id":null,"html_url":"https://github.com/cloud66-oss/unrestful","commit_stats":null,"previous_names":["khash/unrestful"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud66-oss%2Funrestful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud66-oss%2Funrestful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud66-oss%2Funrestful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud66-oss%2Funrestful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloud66-oss","download_url":"https://codeload.github.com/cloud66-oss/unrestful/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248225708,"owners_count":21068078,"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":["rails","rest","rpc"],"created_at":"2024-08-06T08:02:06.589Z","updated_at":"2025-04-10T13:31:31.227Z","avatar_url":"https://github.com/cloud66-oss.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"\u003cimg src=\"http://cdn2-cloud66-com.s3.amazonaws.com/images/oss-sponsorship.png\" width=150/\u003e\n\n# Unrestful\n\nREST is not fit for all use cases. Most of RPC frameworks are too heavy and complicated and require a lot of Ops involvement.\n\nUnrestful is a lightweight simple RPC framework for Rails that can sit next to your existing application. It supports the following:\n\n- Simple procedure calls over HTTP\n- Streaming\n- Async jobs and async job log streaming and status tracking\n\n## Dependencies\n\nUnrestful requires Rails 5.2 (can work with earlier versions) and Redis.\nIn development environments, Unrestful requires a multi-threaded web server like Puma. (it won't work with Webrick).\n\n## Usage\n\nMount Unrestful on your Rails app:\n\n```ruby\nRails.application.routes.draw do\n  # ...\n  mount Unrestful::Engine =\u003e \"/mount/path\"\n  # ...\nend\n```\n\nThis will add the following paths to your application:\n\n```\n/mount/path/rpc/:service/:method\n/mount/path/jobs/status/:job_id\n/mount/path/jobs/live/:job_id\n```\n\nYou can start your Rails app as normal.\n\n## Services and Method\n\nUnrestful looks for files under `app/models/rpc` to find the RPC method. Any class should be derived from `::Unrestful::RpcController` to be considered. Here is an example:\n\n```ruby\nrequire 'unrestful'\n\nmodule Rpc\n\tclass Account \u003c ::Unrestful::RpcController\n\t\tinclude Unrestful::JwtSecured\n\t\tscopes({\n\t\t\t'switch_owner' =\u003e ['write:account'],\n\t\t\t'migrate' =\u003e ['read:account'],\n\t\t\t'long_one' =\u003e ['read:account']\n\t\t})\n\t\tlive(['migrate'])\n\t\tasync(['long_one'])\n\n\t\tbefore_method :authenticate_request!\n\t\t#after_method :do_something\n\n\t\tdef switch_owner(from:, to:)\n\t\t\tfoo = ::AcmeFoo.new\n\t\t\tfoo.from = from\n\t\t\tfoo.to = to\n\n\t\t\treturn foo\n\t\tend\n\n\t\tdef migrate(repeat:)\n\t\t\trepeat.to_i.times {\n\t\t\t\twrite \"hello\\n\"\n\t\t\t\tsleep 1\n\t\t\t}\n\n\t\t\treturn nil\n\t\tend\n\n\t\tdef long_one\n\t\t\treturn { not_done_yet: true }\n\t\tend\n\n\tend\nend\n```\n\nNOTE: All parameters on all RPC methods should be named.\n\n`POST` or `GET` parameters will be used to call the RPC method using their names. For example, `{ \"from\": \"you\", \"to\": \"me\" }` as a HTTP POST payload on `rpc/account/switch_owner` will be used to call the method with the corresponding parameters.\n\nNOTE: Both `rpc/accounts` and `rpc/account` are accepted.\n\nThe three methods in the example above, support the 3 types of RPC calls Unrestful supports:\n\n### Synchronous calls\n\nSync calls are called and return a value within the same HTTP session. `switch_owner` is an example of that. Any returned value will be wrapped in `Unrestful::Response` and sent to the client (this could be a `SuccessResponse` or `FailResponse` if there is an exception).\n\n### Live calls\n\nLive calls are calls that hold the client and send live logs of progress down the wire. They might be cancelled mid-flow if the client disconnects. Live methods should be named in the `live` class method and can use the `write` method to send live information back to the client.\n\n### Asynchronous calls\n\nAsync calls are like sync calls, but return a job id which can be used to track the background job's progress and perhaps follow its logs. Use the `jobs/status` and `jobs/live` end points for those purposes. Async calls should be named in the `async` class method and can use `@job` (`Unrestful::AsyncJob`) to update job status or publish logs for the clients.\n\n## Code\n\nMost of the code for Unrestful is in 2 controllers: `Unrestful::EndpointsController` and `Unrestful::JobsController`. Most fo your questions will be answered by looking at those 2 methods!\n\n## Authorization\n\nBy default Unrestful doesn't impose any authentication or authorization on the callers. However it comes with a prewritten JWT authorizer which can be used by using `include Unrestful::JwtSecured` in your own RPCController. This will look for a JWT on the header, will validate it and return the appropriate response.\n\nThe simplest way to use Unrestful with JWT is to use a tool like Auth0. Create you API and App and use it to generate and use the tokens when making calls to Unrestful.\n\n## Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'unrestful'\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\nOr install it yourself as:\n```bash\n$ gem install unrestful\n```\n\n## Contributing\nContribution directions go here.\n\n## License\nThe gem is available as open source under the terms of the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud66-oss%2Funrestful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloud66-oss%2Funrestful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud66-oss%2Funrestful/lists"}