Pulling a mock server for your APIs out of thin air

Summary A couple of days ago, marcushg mentioned on the #servant IRC channel that one could probably easily use the information available from API types to “derive” a mock implementation of your request handlers that just generates random values of whatever the return type of the handlers are. Julian and I discussed this a bit today and I just went ahead and wrote down our thoughts in a new branch. The result will be explained in this post, but in short, it lets us take a type describing a web API, such as: type API = "user" :> Get '[ JSON ] User and generate request handlers that just respond with random values of the appropriate type, User in our case. In servant/wai terms, this means we get a mock function with the type: mock :: HasMock api => Proxy api -> Server api i.e., “given an API type, please generate a mock server for such an API”. This effectively means “please pull a mock server out of thin air for me”. Out of thin air, really? Not exactly. But let’s start by clearly stating the problem.

Other news I mentioned in a previous post that we had submitted a paper for the Workshop on Generic Programming, co-located with ICFP’15, in Vancouver this year. Well, the paper has been accepted!

Therefore, Julian Arni and/or Andres Löh will be giving a talk about servant there.

In addition to this, Julian Arni recently gave a talk about servant at Curry-On!. The video will be uploaded on their Youtube channel in the upcoming days.

I have submitted a very hands-on servant talk proposal for the Haskell eXchange 2015 in London, and it has been accepted! See you there, folks.

Posted on July 24, 2015 by Alp Mestanogullari