Send a Trackback in Two Lines of Code
Written by James. Published on under the IndieWeb category.
IndieWeb Utils v0.7.2 is out. In this release, we introduce utilities to help you work with Really Simple Discovery and Trackbacks. The additions to the library were inspired by this week's Homebrew Website Club London / Europe meetup. One discussion point was how arXiv supports receiving Trackbacks, an old standard used to notify one site that you have linked to another. Given arXiv's support of Trackbacks -- and its application as a way to build community around research papers -- I decided to add a few helper functions to IndieWeb Utils.
The new Trackback additions to IndieWeb Utils let you discover a Trackback endpoint, send a Trackback, and validate the response from a Trackback. You can send a Trackback in two lines of code! For the full documentation related to all of the new features, check out the library homepage.
To send a Trackback, you can use this code:
from indieweb_utils import send_trackback try: send_trackback( target_url='https://example.com/target', source_url='https://example.com/source', title='My Blog Post', excerpt='', blog_name='My Blog' ) except Exception: raise Exception
The function requires two parameters:
- The URL to which you want to send the Trackback ("the target") and;
- The URL that links to the target ("the source").
You can also specify a title, excerpt, and blog name, although these are optional as per the specification.
In the above example, I have wrapped the
send_trackback() function call in an exception catch block. This will catch any errors that might come up and report them to the console. The library includes two errors:
indieweb_utils.trackback.send.ConnectionError (a connection to the endpoint could not be made) and
indieweb_utils.trackback.send.InvalidStatusCodeError (the endpoint returned a status code that indicates a successful request was not made). General
requests exceptions may also be raised.
I hope this code makes it more convenient for you to send Trackbacks!
P.S. The Webmention protocol also facilitates notifying a site when you have linked to them, but has several improvements (i.e. Webmention has verification steps in the spec to prevent spam, RDF is not required).
Tagged in IndieWeb.
Comment on this post
Respond to this post by sending a Webmention.