Inspecting HTML documents in Haskell playgrounds
In a previous article, we discussed the interactive exploration of network APIs with the Haskell packages
wreq. With the addition of HTML support in playgrounds in Haskell for Mac 1.2.1, we can take this further by adding HTML composition.
For example, using the widely used
blaze-html package, which comes bundled with Haskell for Mac, we can grab the icon of the Haskell for Mac website and add some text with a link as follows.
The resulting HTML document gets rendered in the playground using the system renderer. This provides the same rapid feedback and exploration-friendly environment that we are used to from working with graphics in Haskell playgrounds.
For a more complex example, let's combine HTML composition with the processing of a JSON response from a network endpoint (here, for simplicity, just
httpbin.org). We grab the JSON, parse it, and display the result in a HTML document.
To try this for yourself, just download our example project: Web.hsproj.zip.