MyNixOS website logo
Description

Simple library for network (HTTP REST-like) YAML RPC.

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

YAML-RPC README

Ilya V. Portnov [email protected]

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.

Metadata

Version

1.0.3

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows