Crossposting to DevTo via command line

Posted on January 13, 2020 by Riccardo

Another week, another script in Haskell. It’s probably clear that I’ve found a safe heaven where to play with functional concepts. I do the same at work. Do we need to automate something simple? Maybe just run once and forget it forever? No need to talk more, my fingers are already typing vim script.hs.

Two weeks ago we covered a script to scaffold a blog post. Last week we talked about tweeting a blog post from the command line. Today it’s time to crosspost a local Jekyll-like blog post to

Let’s start from the core of the script, the crosspost function:

Notice that the script uses wreq to perform the HTTP request. The library uses optics heavily (e.g. .~, ^.). We could have used any other library and avoided them easily.

The data sent to the DevTo endpoint is represented by the DevPost type:

We then use optparse-applicative to get the inputs needed from the command line. Its readme is awesome, so please refer to that to learn more.

With that in place, calling the script without the mandatory arguments we get:

We can also call it with --help to get a detailed explanation:

A proper call adds an unpublished blog post on DevTo with all the following filled properly:

  • title;
  • description;
  • tags;
  • canonical_url (the URL of the post on;
  • content.

The whole script is on GitHub.