55°F

Aaron Parecki

  • Articles
  • Notes
  • Projects
  • Sending your First Webmention from Scratch

    Sat, Jun 30, 2018 8:35pm -07:00

    Webmention is one of the fundamental indieweb building blocks. It enables rich interactions between websites, like posting a comment or favorite on one site from another site. This post will walk you through the simplest way to get started sending webmentions to other sites so that you can use your own site to join the conversations happening on the Indie Web.

    So what do you need to walk through this tutorial? We'll use static files and simple command line tools so that you can easily adapt this to any environment or programming language later.

    Get started

    First, we'll create a new HTML file that we'll use to contain the comment to post. At the very minimum, that file will need to contain a link to the post we're replying to.

    <!doctype html>
    <meta charset="utf-8">
    <title>Hello World</title>
    <body>
      <p>in reply to: <a href="https://aaronparecki.com/2018/06/30/11/your-first-webmention">@aaronpk</a></p>
      <p>Trying out this guide to sending webmentions</p>
    </body>
    

    Go ahead and copy that HTML and save it into a new file on your web server, for example: https://aaronpk.com/reply.html. Take your new post's URL and paste it into the webmention form at the bottom of this post. After a few seconds, reload this page and you should see your post show up under "Other Mentions"!

    First Reply

    Making it look better

    That's a great start! But you might be wondering where your comment text is. To make your comment show up better on other peoples' websites, you'll need to add a little bit of HTML markup to tell the site where your comment text is and to add your name and photo.

    Let's take the HTML from before and add a couple pieces.

    <!doctype html>
    <meta charset="utf-8">
    <title>Hello World</title>
    <body>
      <div class="h-entry">
        <p>in reply to: <a class="u-in-reply-to" href="https://aaronparecki.com/2018/06/30/11/your-first-webmention">@aaronpk</a></p>
        <p class="e-content">Trying out this guide to sending webmentions</p>
      </div>
    </body>
    

    Note the parts added in green. These are Microformats! This tells the site that's receiving your webmention where to find specific parts of your post. We first wrap the whole post in a <div class="h-entry"> to indicate that this is a post. Then we add a class to the <a> tag of the post we're replying to, as well as a class to the element that contains our reply text.

    Now, take your URL and paste it into the webmention form below again. After a few seconds, reload the page and your reply should look more complete here!

    Second Reply

    Now we see the text of the reply, and also notice that it moved out of the "Other Mentions" section and shows up along with the rest of the replies!

    Of course this web page still looks pretty plain on your own website, but that's up to you to make it look however you like for visitors visiting your website! As long as you leave the h-entry and other Microformats in your post, you can add additional markup and style the page however you like!

    Adding your name and photo

    Let's make the comment appear with your name and photo now! To do this, you'll need to add a little section to your web page that indicates who wrote the post.

    In Microformats, the author of a post is represented as an h-cards. An h-card is another type of object like h-entry, but is intended to represent people or places instead of posts. Below is a simple h-card that we'll add to the post.

    <div class="h-card">
      <img src="https://aaronpk.com/images/aaronpk.jpg" class="u-photo" width="40">
      <a href="https://aaronpk.com/" class="u-url p-name">Aaron Parecki</a>
    </div>
    

    When we add this h-card into the post we've written, we need to tell it that this h-card is the author of the post. To do that, add the class u-author before the h-card class like the example below.

    <!doctype html>
    <meta charset="utf-8">
    <title>Hello World</title>
    <body>
      <div class="h-entry">
        <div class="u-author h-card">
          <img src="https://aaronpk.com/images/aaronpk.jpg" class="u-photo" width="40">
          <a href="https://aaronpk.com/" class="u-url p-name">Aaron Parecki</a>
        </div>
        <p>in reply to: <a class="u-in-reply-to" href="https://aaronparecki.com/2018/06/30/11/your-first-webmention">@aaronpk</a></p>
        <p class="e-content">Trying out this guide to sending webmentions</p>
      </div>
    </body>
    

    Now when you re-send the webmention, the receiver will find your author name, photo and URL and show it in the comment!

    Second Reply

    Great job! If you've successfully gotten this far, you're now able to comment on things and even RSVP to events using your own website!

    One more detail that you'll want to include on your posts is the date that your post was written. This will ensure the receiving website shows the correct timestamp of your post. If you eventually incorporate this into a static site generator or CMS where you show a list of your replies all on one page, then you'll also want to add a permalink to the individual reply in this post. Typically an easy way to solve both is with the markup below.

    <a href="https://aaronpk.com/reply.html" class="u-url">
      <time class="dt-published" datetime="2018-06-30T17:15:00-0700">July 30, 2018</time>
    </a>
    

    We can add that to the post below the content.

    <!doctype html>
    <meta charset="utf-8">
    <title>Hello World</title>
    <body>
      <div class="h-entry">
        <div class="u-author h-card">
          <img src="https://aaronpk.com/images/aaronpk.jpg" class="u-photo" width="40">
          <a href="https://aaronpk.com/" class="u-url p-name">Aaron Parecki</a>
        </div>
        <p>in reply to: <a class="u-in-reply-to" href="https://aaronparecki.com/2018/06/30/11/your-first-webmention">@aaronpk</a></p>
        <p class="e-content">Trying out this guide to sending webmentions</p>
        <p>
          <a href="https://aaronpk.com/reply.html" class="u-url">
            <time class="dt-published" datetime="2018-06-30T17:15:00-0700">July 30, 2018</time>
          </a>
        </p>
      </div>
    </body>
    

    Automatically sending webmentions

    The last piece to the puzzle is having your website send webmentions automatically when a new post is created.

    This part will require writing some code in your particular language of choice. You'll start by making an HTTP request to get the contents of the page you're replying to, then looking in the response for the webmention endpoint.

    We can simulate this on the command line using curl and grep.

    curl -si https://aaronparecki.com/2018/06/30/11/your-first-webmention | grep rel=\"webmention\"
    

    The response will include any HTTP Link headers or HTML <link> tags that have a rel value of "webmention".

    Link: <https://webmention.io/aaronpk/webmention>; rel="webmention"
    <link rel="webmention" href="https://webmention.io/aaronpk/webmention">
    

    If you get more than one, the first one wins. You'll need to extract the URL from the tag and then send the webmention there.

    Sending a webmention is just a simple POST request to the webmention endpoint with two URLs: the URL of your post (source) and the URL of the post you're replying to (target).

    curl -si https://webmention.io/aaronpk/webmention \
      -d source=https://aaronpk.com/reply.html \
      -d target=https://aaronparecki.com/2018/06/30/11/your-first-webmention
    

    The only significant part of the response is the HTTP response code. Any 2xx response code is considered a success. You'll most often receive either a 202 which indicates that the webmention processing is happening asynchronously, or if the receiver processes webmentions synchronously and everything worked, you'll get a 201 or 200.

    In practice, you'll probably use a library for discovering the endpoint and sending the webmention, so here are a few pointers to start you out in a variety of languages.

    • Ruby
    • PHP
    • Node
    • Python
    • Go
    • Elixir
    • ...more on indieweb.org

    Hopefully this guide was helpful to get you going in the right direction!

    If you want to dive into the weeds, check out the Webmention spec as well as more details on reply posts.

    When you want to put your automatic webmention sending implementation to the test, try sending webmentions to all of the links on the test suite, webmention.rocks!

    If you have any questions or run into any issues, feel free to ping me or anyone else in the IndieWeb chat!

    #webmention #indieweb #tutorial #microformats
    Sat, Jun 30, 2018 8:35pm -07:00
    11 likes 1 repost 4 bookmarks 11 replies 25 mentions
    • Tom
    • Kartik Prabhu
    • Malcolm Blaney
    • Peter Stuifzand
    • Sebastiaan Andeweg
    • Eli Mellen
    • Marty McGuire
    • Ryan Barrett
    • gRegor Morrill
    • Robert van Bregt
    • Robert van Bregt
    • Robert van Bregt
    • Peter Stuifzand
    • Jeremy Keith
    • Serena
    • John Johnston johnjohnston.info/blog
      Trying out this guide to sending webmentions step 3 & curl
      Mon, Jul 9, 2018 2:33am -07:00
    • digital.st
      Trying out this guide to sending webmentions!
      Wed, Jul 11, 2018 12:41am -07:00
    • Aaron Parecki aaronpk.com
      Trying out this guide to sending webmentions
      Sat, Jun 30, 2018 5:15pm -07:00
    • Douglas Beal dougbeal.com
      🎉
      Sat, Jun 30, 2018 9:34pm -07:00
    • Amit Gawande www.amitgawande.com

      I always wanted to sort out my webmentions and the respective microformats in reply posts. Aaron’s post could not have arrived at a better time. Here’s hoping it comes out the way I want it to.

      Sun, Jul 1, 2018 3:35am -07:00
    • Aaron Davis readwriterespond.com
      💬 Sending your First Webmention from Scratch
      Sun, Jul 1, 2018 9:01pm +10:00
    • Shane Hudson shanehudson.net
      I need to rewrite the webmention plugin I was using, upgraded to Craft 3 and no longer compatible.
      Sun, Jul 1, 2018 4:24pm +00:00 (via brid-gy.appspot.com)
    • john johnjohnston.info/blog/author/john
      Re: Sending your First Webmention from Scratch
      Mon, Jul 9, 2018 10:57am +00:00
    • Stephen McCready www.stephenmccready.asia
      试用本指南发送 webmentions
      Fri, Jul 20, 2018 11:58pm -07:00
    • Florian Rang x.rang.de/contact
      Trying out this guide to sending webmentions. Cool stuff!
      Sun, Jul 29, 2018 12:43pm +02:00
    • Scott Gruber scottgruber.me

      Sites to help test

      • fed.brid.gy
      • brid.gy
      Wed, Aug 22, 2018 9:22pm -07:00

    Other Mentions

    • www.wrke.online
      Kim Landwehr
      Sun, Jul 1, 2018 1:14pm -07:00
    • Chris Aldrich alistapart.com/author/chrisaldrich
      Webmentions: Enabling Better Communication on the Internet
      Thu, Jul 19, 2018 7:38am -07:00
    • stephenmccready.asia
      Fri, Jul 20, 2018 3:39am -07:00
    • fulcrumaccess.com
      Peter Abramowicz
      Fri, Jul 20, 2018 9:00am -07:00
    • floridafruitgeek.com
      Fri, Jul 20, 2018 12:40pm -07:00
    • Kartik Prabhu kartikprabhu.com
      liked aaronparecki.com/2018/06/30/11/…
      Nice short guide to sending webmentions.
      Sun, Jul 1, 2018 3:43am +00:00 (via brid-gy.appspot.com)
    • Chris Aldrich www.boffosocko.com
      👓 Sending your First Webmention from Scratch | Aaron Parecki
      Sat, Jun 30, 2018 11:05pm -07:00
    • Amit Gawande www.amitgawande.com
      In reply to aaronparecki.com/2018/06/30/11/…

      I always wanted to sort out my webmentions and the respective microformats in reply posts. Aaron’s post could not have arrived at a better time. Here’s hoping it comes out the way I want it to.
      Sun, Jul 1, 2018 10:47am +00:00 (via brid-gy.appspot.com)
    • Adactio Links adactio.com/links
      Sending your First Webmention from Scratch • Aaron Parecki aaronparecki.com/2018/06/30/11/…
      Sun, Jul 1, 2018 11:07am +00:00 (via brid-gy.appspot.com)
    • Kevin Marks known.kevinmarks.com/profile/kevinmarks
      Aaron put together a nice clear guide to creating and sending your first webmention https://aaronparecki.com/2018/06/30/11/your-first-webmention #Indieweb
      Sun, Jul 1, 2018 4:21pm +00:00
    • Peter Rukavina https://images.ruk.ca/picture-of-peter-rukavina.jpg ruk.ca/about-peter-rukavina
      Digging into Webmention
      Thu, Jul 5, 2018 10:22pm -07:00
    • Chris Baughman cmb.ninja
      Here is yet another cool little known #html feature called #webmentions aaronparecki.com/2018/06/30/11/… @aaronpk really does a nice job of introducing it.
      Tue, Jul 10, 2018 10:06pm +00:00 (via brid-gy.appspot.com)
    • tams sokari tamssokari.wordpress.com
      aaronparecki.com/2018/06/30/11/…
      Sat, Jul 14, 2018 11:54pm +00:00 (via brid-gy.appspot.com)
    • David Shanske david.shanske.com
      An Indieweb Podcast: Episode 8 – Interflux
      Mon, Jul 16, 2018 8:09am -04:00
    • keith•j•grant keithjgrant.com
      An introduction to Webmentions from @aaronpk

      aaronparecki.com/2018/06/30/11/…
      Mon, Jul 16, 2018 2:15pm +00:00 (via brid-gy.appspot.com)
    • Chris Aldrich www.boffosocko.com
      An Indieweb Podcast: Episode 8 Interflux
      Mon, Jul 16, 2018 8:10am -07:00
    • Fabian Steeg fsteeg.com
      “This post will walk you through the simplest way to get started sending webmentions to other sites […] We’ll use static files and simple command line tools” aaronparecki.com/2018/06/30/11/…
      Thu, Jul 19, 2018 9:34pm +00:00 (via brid-gy.appspot.com)
    • Kendall Giles www.kendallgiles.com
      And Now to Tackle Webmentions
      Mon, Jul 23, 2018 9:05am +00:00
    • Greg McVerry jgregorymcverry.com
      My #EDU522 Subjectives
      Thu, Aug 2, 2018 8:18pm -04:00
    • Greg McVerry jgregorymcverry.com
      My #EDU522 Subjectives
      Thu, Aug 2, 2018 8:18pm -04:00
    • Chris Aldrich www.boffosocko.com
      🎧 2ToPonder Episode One | INTERTEXTrEVOLUTION
      Mon, Aug 6, 2018 1:29pm -07:00
    • Deluvi deluvi.com
      Implementing Webmention on a static website
      Thu, Aug 9, 2018 2:00pm +02:00
    • Sylvain Lesage rednegra.net
      El futuro de los comentarios (ojala) son las "menciones web".

      Estándar oficial W3C, descentralizado, con un concepto genial: comentas un artículo de donde quieres (TW, FB, tu blog) y aparece abajo del artículo original.

      Desarrollador/a: aquí está la base
      aaronparecki.com/2018/06/30/11/…
      Fri, Aug 17, 2018 1:36am +00:00 (via brid-gy.appspot.com)
    • Norman Walsh nwalsh.com
      Webmention implemented
      Fri, Aug 24, 2018 5:00pm -07:00
    • Jason Ho jasonho.ca
      Jason Ho

      in reply to: @aaronpk

      Trying out this guide to sending webmentions

      Mon, Aug 27, 2018 12:00am +08:00
Posted in /articles using quill.p3k.io

Hi, I'm Aaron Parecki, co-founder of IndieWebCamp. I maintain oauth.net, write and consult about OAuth, and am the editor of several W3C specfications. I record videos for local conferences and help run a podcast studio in Portland.

I wrote 100 songs in 100 days! I've been tracking my location since 2008, and write down everything I eat and drink. I've spoken at conferences around the world about owning your data, OAuth, quantified self, and explained why R is a vowel.

Follow
  • Okta Developer Advocate
  • IndieWebCamp Founder
  • W3C Editor
  • Stream PDX Co-Founder
  • backpedal.tv

  • W7APK
  • ⭐️ Life Stack
  • All
  • Articles
  • Bookmarks
  • Notes
  • Photos
  • Replies
  • Reviews
  • Sleep
  • Travel
  • Contact
© 1999-2018 by Aaron Parecki. Powered by p3k. This site supports Webmention.
Except where otherwise noted, text content on this site is licensed under a Creative Commons Attribution 3.0 License.
IndieWebCamp Microformats Webmention W3C HTML5 Creative Commons