{"id":22750254,"url":"https://github.com/webix-hub/webix-remote-js","last_synced_at":"2025-04-14T12:53:16.997Z","repository":{"id":65379281,"uuid":"54951094","full_name":"webix-hub/webix-remote-js","owner":"webix-hub","description":"Simple RPC for NodeJS and Webix UI","archived":false,"fork":false,"pushed_at":"2018-06-14T16:45:18.000Z","size":22,"stargazers_count":5,"open_issues_count":6,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T02:03:17.427Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://webix.com","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/webix-hub.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":"2016-03-29T06:21:50.000Z","updated_at":"2023-05-16T12:43:15.000Z","dependencies_parsed_at":"2023-01-20T08:45:46.345Z","dependency_job_id":null,"html_url":"https://github.com/webix-hub/webix-remote-js","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webix-hub%2Fwebix-remote-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webix-hub%2Fwebix-remote-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webix-hub%2Fwebix-remote-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webix-hub%2Fwebix-remote-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webix-hub","download_url":"https://codeload.github.com/webix-hub/webix-remote-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248885448,"owners_count":21177624,"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-12-11T04:13:19.808Z","updated_at":"2025-04-14T12:53:16.952Z","avatar_url":"https://github.com/webix-hub.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Webix Remote - Nodejs\n---------------------\n\n\n[![Build Status](https://travis-ci.org/webix-hub/webix-remote-js.svg?branch=master)](https://travis-ci.org/webix-hub/webix-remote-js)\n[![npm version](https://badge.fury.io/js/webix-remote.svg)](https://badge.fury.io/js/webix-remote)\n[![Join the chat at https://gitter.im/webix-hub/webix](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/webix-hub/webix) \n\n\nSimple RPC for NodeJS and Webix UI\n\n\n### How to install\n\n```\nnpm install webix-remote\n```\n\n### How to use\n\n#### On server side\n```js\nvar remote = require(\"webix-remote\");\nvar api = remote.server();\n\napi.setMethod(\"add\", function(a,b){\n\treturn a+b;\n});\n\napi.setMethod(\"helpers\", {\n\tadd: (a,b) =\u003e a+b,\n\tmul: (a,b) =\u003e a*b\n});\n\nexpress.use(\"/api\", api.express());\n```\n\n#### On client side\n\n```html\n\u003cscript src='/api'\u003e\u003c/script\u003e\n\u003cscript\u003e\nwebix.remote.sum(1,2).then(result){\n\tconsole.log(result);\n});\n\n//or in the sync way\nvar sum = webix.remote.sum(1,2).sync();\n\u003c/script\u003e\n```\n\n#### Special parameters\n\n- $req - request object\n\n```js\napi.setMethod(\"add\", function(a,b,$req){\n\treturn a+b+$req.session.userBonus;\n});\n//on client - webix.remote.add(1,2);\n```\n\n#### Adding static data\n\nYou can define some static data which will be available on client side. It is a good place for session data, which need to be shared with a client-side code.\n\nWarning - the data generation method will be called only once, during the api initialization. \n\n```js\n//server\napi.setData(\"$user\", function($req){\n\treturn $req.user.id;\n});\n\n//client\nvar user = webix.remote.$user;\n```\n\n#### API access levels\n\nYou can limit api to user's with defined access level. \n\n```js\n//only user with 'admin' role will be able to call the method\napi.setMethod(\"admin@add\", function(a,b){\n\treturn a+b;\n});\n```\n\nAccess level is defined in next way\n\n- all methods withouth access modificator is allowed by default\n- if req.session.user exists, methods with \"user\" modificator is allowed\n- if req.session.user.role exists, methods with role modification is allowed\n\n```js\n//req.session = { user: { role:\"admin,levelB\"}}\n\napi.setMethod(\"user@add1\", (a,b) =\u003e a+b ); //allowed\napi.setMethod(\"admin@add2\", (a,b) =\u003e a+b ); //allowed\napi.setMethod(\"levelC@add3\", (a,b) =\u003e a+b ); //blocked\n```\n\nYou can define your custom logic though\n\n```js\napi.$access = function(){\n\treturn { \n\t\tuser : !!req.user,\n\t\tadmin: req.user \u0026\u0026 req.user.id == 1 \n\t};\n};\n```\n\n### License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebix-hub%2Fwebix-remote-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebix-hub%2Fwebix-remote-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebix-hub%2Fwebix-remote-js/lists"}