Skip to content

haskell-mafia/corba

Repository files navigation

corba

screen shot 2017-10-18 at 3 12 30 pm

"It sounds an awful lot like you're reinventing CORBA" - Pierce, 2017

Corba is an extremely simple, naive RPC system. It is intended to automate a bunch of busywork around Ambiata service communication.

Given a service definition and a set of Machinator datatypes, it will generate Haskell datatypes, message codecs (JSON for now), WAI middleware, a client library, and documentation. This addresses a bunch of process problems:

Example

Service definition:

Service {
  serviceName = ServiceName "greeting"
, serviceMethods = [
    Method {
        methodName = MethodName "hello"
      , methodRequest = TypeName "HelloRequest"
      , methodResponse = TypeName "HelloResponse"
      }
  , Method {
        methodName = MethodName "goodbye"
      , methodRequest = TypeName "GoodbyeRequest"
      , methodResponse = TypeName "GoodbyeResponse"
      }
  ]
}

Data definition:

data HelloRequest =
    HelloRequestV1 String
  | HelloRequestV2 String Message

data HelloResponse =
    HelloResponseV1 ResponseMsg

record Message = {
  message : String
}

data ResponseMsg =
    Worked
  | Failed

-- (Ditto for the Goodbye Request
--  and Response definitions.)

Generated abstract interface:

data GreetingService m = GreetingService {
    hello :: HelloRequest -> m HelloResponse
  , goodbye :: GoodbyeRequest -> m GoodbyeResponse
  }

Generated WAI middleware:

greetingMiddleware :: Route -> GreetingService (ExceptT ErrorMessage IO) -> (Wai.Application -> Wai.Application)

Generated client:

greetingClient :: Monad m => GreetingService (HttpApi m)