Sharing social interactions with Micropub
Written by James. Published on under the IndieWeb category.
One of the IndieWeb words I hear every now and again is "Micropub." I must have heard it or seen it dozens of times before actually understanding what it was. The word went in one ear and out the other. I recently found myself with an interest in taking on a project related to this website. When thinking about what to do, I stumbled upon Micropub. I learned that Micropub is a standard that you can use to post content on your site. Micropub describes, in detail, how you can post to your personal website from a "client" as long as you have a "server" that can read requests from the client and translate them into posts.
Through the power of Micropub and its clearly-defined specifications, I have added some "social interactions" to this blog. These are methods through which I can interact with other content on the web. So far, I support:
- Coffee logging
In this article, I am going to briefly explain why I decided to add Micropub support to this blog.
What is Micropub?
Rather than come up with my own definition, I shall defer to the wonderful IndieWeb wiki:
"Micropub is an open API standard W3C Recommendation for creating, editing, and deleting posts on websites, like on your own domain, supported by numerous third-party clients, CMSs, and social readers."
The Micropub recommendation defines a client-server framework. A client creates a request that contains information about a post you want to add to your site. A common example is likes. Many Micropub clients let you add likes to your website. The client takes a URL and turns it into a "like" microformat. This is then sent to a server of your choosing. You can host your own or rely on an existing Micropub server. The server takes all of the information from the client and turns it into a post. I will explain how this works for me in the "My Micropub setup" section later in this post.
Here is an example of a few posts I have created using Micropub that appear on my new blog social page:
Social networks, discoverability, and sharing reactions
While social networks are excellent ways to share information in a moment, it's easy to lose track of what you have shared. Instagram, the social network which I use the most, does not exactly provide a seamless way to look at past stories. I know you can, it's just not obvious. I have posted many stories and I can't remember what most of them are. Nor have I ever had the inclination to dig through stories to cite them. Once I did try to export a few stories but the process was very manual. So all of those posts are largely ephemeral.
What got me thinking about Micropub was I wondered how I could keep a log of the coffees I had consumed. I usually post about the coffees I am drinking on Instagram but I don't really have a log of them. Each post is now in my stories history which I expect I will only rarely look at.
I wanted to create a page on my site that listed each different coffee I had tried (referring to different bags of coffee from roasters rather than individual cups of coffee). A spreadsheet would do but I didn't want to do that. I could manually create posts on my site but that would take time and would require me to be sitting at my computer. After reading about Micropub, I found there was a standard I could use to define the means by which I could create and process individual posts that would collectively make up a coffee log.
As I got thinking about Micropub, I noticed that its potential lay not just in helping me keep track of the coffees I had consumed. As my understanding of the protocol developed, I found that I could create likes, bookmarks, and really any type of content I wanted on my site.
My Micropub setup
Earlier in this post, I mentioned that one needs both a client and a server to make Micropub. While there are plenty of examples of clients and servers online, I wanted to challenge myself so I decided to build my own. I also noticed that there was not a Micropub client that would let me process a coffee log post in the way I wanted (where I could share the name of the roaster who roasted a coffee, the varietals in a coffee, and more).
My Micropub client supports all of the types of posts mentioned at the start of this article, from likes to bookmarks to coffee logging. Let's take the "coffee logging" post as an example. My client contains a form that asks me for the name of a coffee, a description, and some meta information about the coffee itself. Here is what the client looks like:
When I submit this form, the client takes all of my information and turns it into a request that can be fired to my Micropub server. The client also uses the Micropub media endpoint standard to save any images that have been uploaded. This happens separately from the request to the server that creates my post. First, I upload any images. Then, I get the image information and attach it to the request to create the post. If I haven't added an image, the client skips these steps and immediately sends a request to the client to create the coffee log post.
My Micropub server then completes a number of tasks. Roughly, these are:
- Verify the person sending the request is authenticated. This is done using IndieAuth, a way in which you can authenticate with a service using your domain name.
- Verify the request is of the right type (form encoded, JSON, or multipart form data).
- Identify the post type (a coffee post, a like, a bookmark, etc.)
- Get all of the information from the post given whatever type of post I have created (e.g.. a coffee log, a like post, a checkin). Here are three examples of this stage:
- In coffee posts, I look for coffee names, descriptions, roaster information, coffee varietals, and more.
- In like posts, I look for the URL of the post I have liked.
- In checkin posts, I look for the name of the venue in which I have checked in, latitude and longitude coordinates, a photo, and more.
- Turn the information from the post sent by the client into a markdown file with some front matter. The front matter contains all the information that is not post content. My blog has templates that can read this front matter and translate it into a working page.
- Using PyGitHub, a Python library that lets you interface with GitHub, I upload the markdown file.
- I tell the user the post has been created and send a Location header in that request to say where the new content is.
- Within a few minutes—the time it takes GitHub to rebuild my website to add the new post—my post has been created.
These are high-level steps. For more information on implementation, I defer you to the Micropub specification. I would also recommend checking out the high-level implementation guide on the IndieWeb wiki if you plan on building a Micropub server yourself. This guide gave me some useful context that massively helped me build my Micropub server.
My Micropub client and server are still very much in development. There are still a number of bugs I want to fix and other features that I want to add. To help me understand issues and fix them, I have been using the micropub.rocks test suite. I'd recommend checking out micropub.rocks if you are building either a client or a server. While not all tests may apply depending on what you want to do, the test suite will help you make the main features of your server or client more robust and help you deepen your understanding of the Micropub specification in practice.
Using Micropub to share posts
I now have a new Social page on my blog which shows all of the social interactions I support. For the last day or two I have been sharing likes and bookmarks. I like being able to create a like or a bookmark in a few clicks. The alternative would be manually creating a post on my blog and pushing it to Git. This would take significantly longer than using my Micropub client. I have also written a few replies to blog posts using Micropub. I have a bookmarklet, inspired by many of those available in existing Micropub clients like Quill and Micropublish, that lets me easily like, reply to, or bookmark a post.
Developing my Micropub client and server has taken a lot of time and I still have work to do on getting everything working as I would like. But, I am excited at the opportunities Micropub gives me to share data on my personal website. Micropub makes sharing social interactions on my blog seamless. I can say I liked a blog post and save it for future use. Anyone can see the post so the posts I like don't just end up in my browser bookmarks.
Do you support Micropub on your blog? Do you have any questions about my implementation? I'd love to hear from you. To respond, you can either send a Webmention to this post or you can email me at email@example.com. I am still learning about Micropub so I'm looking to chat with more people about it.
Read more content like this
Check out the other posts I have written related to this article.
- Micropub and Publishing Content
- Sharing social interactions with Micropub
- My New Social Pages
- Adding reply context to my social pages
- Improving my social reader experience on mobile
Powered by Novacast
Comment on this post
Respond to this post by sending a Webmention.