Sending WebSub notifications
During IndieWebCamp DĂĽsseldorf this year, I implemented sending WebSub notifications, to immediately notify potential subscribers, whenever my (Atom) feeds update.
I wanted this,
- to have new content instantly show up in WebSub-supported feed readers, and
- to (hopefully) reduce the amount of requests feed readers otherwise need to send to manually fetch the information.
Ever since I started making my own feed reader, I noticed how nice and efficient it is to have the sources simply notifying the application.
As a publisher, it’s actually not that hard to make this happen. Here’s what I have done, which is the minimal steps:
- Decide on one of the public and free WebSub hubs.
- Signal WebSub support by adding one
<link>
tag to your feed(s) (and/or add a HTTP header). - Trigger distribution of your new blog post(s) by sending one
POST
request to your chosen hub.
1. Deciding on a WebSub hub
The IndieWeb wiki has a good overview of available hubs. I chose the first one on the list: https://pubsubhubbub.superfeedr.com.
There’s no need to register with such a hub. Just use this by specifying its URL in your feed files.
2. Adding a <link>
tag to your feed(s)
Add something like this to each of your feeds:
<link rel="hub" href="https://pubsubhubbub.superfeedr.com"/>
Ideally and additionally or alternatively, add the following HTTP Link
header lines:
Link: <https://pubsubhubbub.superfeedr.com/>; rel="hub"
Link: <https://danielpietzsch.com/feed.atom>; rel="self"
I currently don’t have the ability to manually set my HTTP
headers, so I only went with the <link>
tag.
There’s also more detailed information on the IndieWeb wiki: How to publish and consume WebSub.
3. Send a POST
request to your hub, whenever your feed(s) update
I currently use an iOS/iPadOS shortcut to send this request manually, after each time my site was successfully built and uploaded by the GitLab pipeline. So, I use Shortcuts’ “Get Contents of URL” task to send a POST
request like this:
https://pubsubhubbub.superfeedr.com/?hub.mode=publish&hub.url[]=https://danielpietzsch.com/notes/feed.atom&hub.url[]=https://danielpietzsch.com/feed.atom&hub.url=https://danielpietzsch.com/articles/feed.atom
Notice, that I send URLs of multiple feeds with one request. With this syntax, I tell the hub to notify subscribers of all those feeds simultaneously.
Guess what? More info on the wiki again: Notify the hub of new content.
Make sure your cache is fresh and the feed’s updated
date is up to date. Otherwise the hub might think there’s nothing new there and won’t notify anyone.
You can also watch my video demonstration from IWC.