Code Monkey home page Code Monkey logo

wsrpc's Introduction

WebSocket RPC application

Intro

This library enables to communicate with 'gen_server's via WebSocket or HTTP using JSON formatted messages. It is supposed that callback module implementing 'gen_server' behavior uses erlang records to represent a messages passed to 'gen_server:handle_call'.

Plug your service into WSRPC

To make your gen_server's callable via 'wsrpc' you must:

  • implement resolver module
  • configure 'wsrpc' application in a configuration file
  • provide record mapping info

The resolver is a module with a function:

:::erlang
-spec resolve(ServicePath :: [ binary() ]) -> {gen_server, pid()} .

Actually this function may reside in any module you want, the only purpose of it to know how to find | activate | instantiate a gen_server process.

The second step is to make 'wsrpc' know about your gen_server's i.e. about your resolver. For example let we have an application 'my_app' in which we have a resolver 'my_services', then the configuration section may look like following:

:::erlang
{wsrpc, [	{http_port, 8484}, 
 	     	{apps, [
		{my_app, [ {services, [my_services]} ] } 
	       ] }
     ] },

The third step is described in a next section.

Provide record mapping information

WSRPC require some help from you to be able to map record to JSON and back. You must support a special additional call in your 'gen_server':

:::erlang
handle_call({get_type, RecordName}, _From, State) ->
	{reply, [field1, field2, field3] , State};

I.e. your server must be ready to reply a field list for requested record name if your server uses this record in its calls. All records in use, will be mapped to/from JSON in a strict way. For example let we have a record like:

:::erlang
#message{ id = 0, operation = "call_smth_useful", args = ["data1", "data2"]}

then it will be mapped to JSON as:

 { "id"        : 0,
   "type"      : "message",
   "operation" : "call_smth_useful", 
   "args"      : [ "data1", "data2" ] }

and vise versa.

WebSocket mode

TBD

wsrpc's People

Contributors

vjache avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

mkuznetsov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.