Saturday, February 22, 2014

Parsec-like expressions to read web service parameters and generate the response

A haskell formlet is the combination of a parameter parser plus a writer to generate HTTP output

I use this similarity to create parsec-like combinators that use the formlet monad in MFlow (the View monad)  to parse the web service parameters and to generate the output.

This service below implements a service that sum or multiply two Int-egers.

main = runNavigation "apiparser" . step . asks $ do rest "sum" ; disp $ (+) <$> wint "t1" <*> wint "t2" <|> do rest "prod" ; disp $ (*) <$> wint "t1" <*> wint "t2" <?> do -- blaze Html h1 << "ERROR. API usage:" h3 << "http://server/api/sum?t1=[Int]&t2=[Int]" h3 << "http://server/api/prod?t1=[Int]&t2=[Int]" where asks w= ask $ w >> stop
See a more complete explanation and working examples here:
By the way:
The blogger editing system is the ugliest and unfriendly thing invented by mankind. It is not worth being a Google product. The feedback link does not work.
Post a Comment