yaml-rpc: Simple library for network (HTTP REST-like) YAML RPC

[ bsd3, library, network ] [ Propose Tags ] [ Report a vulnerability ]

This library aimed to organize remote procedure call (RPC) over HTTP protocol, using YAML as data serialization format.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.2, 0.3, 0.3.1, 1.0, 1.0.1, 1.0.2, 1.0.3
Dependencies aeson (>=0.7.0.3), base (>=3 && <=5), bytestring (>=0.10.0.2), containers, http-client (>=0.3.3.1), http-types (>=0.8.5), lens (>=4.1), template-haskell, text (>=1.1.1.3), th-lift, transformers (>=0.3.0.0), unordered-containers (>=0.2.4.0), vector (>=0.10.11.0), wreq, yaml [details]
License BSD-3-Clause
Author Ilya V. Portnov
Maintainer portnov84@rambler.ru
Category Network
Home page http://redmine.iportnov.ru/projects/yaml-rpc
Source repo head: git clone git@github.com:portnov/yaml-rpc.git
Uploaded by IlyaPortnov at 2014-07-03T14:07:16Z
Distributions
Reverse Dependencies 3 direct, 0 indirect [details]
Downloads 5358 total (18 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Successful builds reported [all 1 reports]

Readme for yaml-rpc-1.0.3

[back to package description]

YAML-RPC README

Ilya V. Portnov portnov84@rambler.ru

The yaml-rpc package contains a small library to organize remote procedure call (RPC) over TCP/IP network, using JSON as data serialization format.

RPC server should supply a set of "RPC methods", which are simply functions :: a -> b -> ... -> IO c. Arguments must be of class ToJSON (defined in aeson package); result must be of class FromJSON (defined in aeson package too). One can of cause use GHC Generics mechanism to derive needed instances. yaml-rpc package provides a (TemplateHaskell) function Network.YAML.TH.Server.makeAPI to generate API description for server. Such API can be automatically written to file in simple YAML format by using function Network.YAML.TH.Server.writeAPI. It is possible to write different servers, which will use generated API description and provide HTTP REST JSON services with that API. Currently there is only one implementation using scotty package; it is provided by yaml-rpc-scotty package. Please see yaml-rpc-scotty/Test/{Server.hs, TestAPIImpl.hs} files for example usage.

RPC client calls that functions via HTTP REST JSON interface. So, it can be used either from Haskell or from any other environment. For example, it can be easily used from JavaScript with JQuery or another framework. For Haskell, yaml-rpc package provides a function Network.YAML.Caller.call to call any method via HTTP REST JSON interface. Moreover, a (TemplateHaskell) function Network.YAML.TH.Client.useAPI function will read API description from file (in YAML format) and generate wrapper methods for calling respective remote methods. Please see Test/Client.hs for example usage.

Currently, only one-connection-per-call mode is supported by Caller module. There are plans to implement persistent connection support.

API description files can contain not only methods description, but also data types description. Types description can be also automagically generated from usual Haskell definitions and written to API description file. Then, when reading that API description file, usual Haskell data type definitions are generated.

Please see test.api file for example of API description format.

On the server side, usual workflow is as following:

  • Write some number of API data types and functions to be exposed.
  • Call makeAPI function to generate API description.
  • Call writeAPI function to write API description to file.
  • Call generateDispatcher function on generated API to generate function dispatch :: Text -> Maybe (Value -> IO Value). This function will be used by any server implementation.
  • Launch any server implementation and provide it by dispatch function.

On the client side, usual workflow is as following:

  • Receive API description file from service provider.
  • Call useAPI function on that file; it will generate data types definitions and wrapper functions to call all methods declared in file.
  • Call generated wrappers.

Depends: ghc >= 7.6, yaml, template-haskell, th-lift, wreq, lens, scotty.