Adventures in Haskell (Servant)

2020-10-03rchaskellfp

October 3, 2020

It is the end of my second week at RC, and I’ve decided to have a go at building a small project using Servant, the Haskell webserver library. The idea is to construct a PDF server — let’s call it pdfServer.io — for files written in MiniLaTeX. The flow of data goes like this:

  1. A user requests a PDF of a MiniLaTeX document.
  2. minilatex.lamdera.app sends a POST request to pdfServer.io with the source text of the document.
  3. pdfServer.io runs xelatex on the data received and stores the resulting PDF file.
  4. pdfServer.io replies to the POST request with a URL, https://pdfServer/pdf/ab1234, where ab1234 is the id of the generated PDF file.
  5. When the URL is received by the MiniLaTeX app, it presents it as a clickable link.
  6. The user clicks on the link, making a GET request to pdfLatex.io.
  7. pdfLatex.io replies with the PDF file, which either loads in the browser or is downloaded to disk, depending on the user’s browser and settings.

The documentation for Servant is especially good. Here are the basic references, together with some examples

I am still studying the code and the docs, and am trying out little examples. Hope to get the project going shortly. But as a taste of how awesome Servant is, try out the minimal example and also the example with data persistence (via sqlite). Then take a look at the tutorial, which explains how one can do so much with so few lines of code.