ActionCable 在 Rails 5 RESTful API 开发中的使用? [英] ActionCable usage in Rails 5 RESTful API Development?
问题描述
我第一次尝试创建一个 RESTful API.
I am trying to create a RESTful API for the first time.
使用 Action Cable 发送请求(客户端到服务器)和响应(服务器到客户端).
Sending Request(Client to Server) and Response(Server to Client) using Action Cable.
如何从其他应用程序(如 Android/iOS 应用程序、Web App'n 或桌面应用程序'n)发送请求并响应应用程序.
How to send request from other Applications(like Android/iOS App, Web App'n or Desktop App'n) and give response to the application.
我在普通的 Web 应用程序中使用了 Action Cable.
I have used Action Cable in normal Web Application.
请给我提供一些关于 Rails 5 RESTful API 中 ActionCable 使用指南的链接.
Please provide me some links with guides of ActionCable usage in Rails 5 RESTful API.
提前致谢.
推荐答案
这里是使用 Action Cable 作为 Restful API 的细节.
Here is the detail to use Action Cable as Restful API.
使用以下 JSON 进行订阅.
Use following JSON for subscription.
{命令":订阅",标识符":{频道":CHANEL_NAME"}}
{ "command": "subscribe", "identifier": { "channel": "CHANEL_NAME" } }
使用以下 JSON 进行模型订阅.
Use following JSON for model subscription.
{命令":订阅",标识符":{"频道": "CHANEL_NAME",post_id":1}}
{ "command": "subscribe", "identifier": { "channel": "CHANEL_NAME", "post_id": 1 } }
使用以下 JSON 调用频道中的任何方法.
Use following JSON to call any method in channel.
{命令":消息",标识符":{频道":CHANEL_NAME"},数据": {"action": "ACTION_NAME",....}}
{ "command": "message", "identifier": { "channel": "CHANEL_NAME" }, "data": { "action": "ACTION_NAME", .... } }
这篇关于ActionCable 在 Rails 5 RESTful API 开发中的使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!