Micropub

From IndieWeb
Jump to: navigation, search

Micropub is an open API standard that is used to create posts on one's own domain using third-party clients. Web apps and native apps (e.g. iPhone, Android) can use Micropub to post short notes, photos, events or other posts to your own site.

Contents


Background

The Micropub vocabulary is derived directly from the Microformats vocabulary. Micropub is meant to be a serialization of Microformats that can be submitted as an HTTP POST. The method for developing new Micropub vocabularies is to look at the Microformats representation and work backwards.

Syntax

Similar to how microformats has a relatively small ruleset for parsing HTML documents into a data structure, Micropub defines a small set of rules to interpret HTTP POST and GET requests as Micropub commands. Where Microformats does not require changing the parsing rules to introduce new properties of an object such as an h-entry, Micropub similarly does not require changing parsing rules to interpret requests that may correspond to different post types, such as posting videos vs "likes".

The Micropub syntax describes how to interpret HTTP POST and GET requests into a useful action the server can take.

The full specification can be read at http://micropub.net/draft/

Overview

All Micropub requests to create posts are sent as form-encoded[1], multipart form-data [2], or JSON encoded HTTP requests. Responses typically do not include a response body, indicating the needed information (such as the URL of the created post) in HTTP headers. When a response body is required, it is returned as either form-encoded or JSON[3], depending on the HTTP Accept[4] header.


How to implement

How to implement the Micropub API, both in a client that can discover an endpoint and publish to it, and on a server to support an endpoint to create/update/delete posts in response.

Endpoint Discovery

It should be possible to configure an API client by authenticating as your domain name using IndieAuth. After signing in, your domain needs a way to specify the API endpoint the client will use to create new posts.

Add a <link> tag in the HTML head of your home page, or send an HTTP Link header.

HTTP Header

Link: <https://example.com/micropub>; rel="micropub"

HTML Head

<link rel="micropub" href="https://example.com/micropub">

Authentication

Micropub requests are authenticated by including a Bearer Token in either the HTTP header or a form-encoded body parameter as described in the OAuth Bearer Token RFC.

Authorization should be handled via the IndieAuth protocol, built on top of OAuth 2.0. See obtaining-an-access-token for more details. An app that wants to post to a user's Micropub endpoint will need to obtain authorization from the user in order to get an access token.

HTTP Header

Authorization: Bearer XXXXXXXX

Form-Encoded Body Parameter

access_token=XXXXXXXXX

Scope

The client may request one or more scopes during the authorization request. It does this according to standard OAuth 2.0 techniques, by passing a space-separated list of scope names in the authorization request.

The authorization server must indicate to the user any scopes that are part of the request, whether or not the authorization server recognizes the scopes. The authorization server may also allow the user to add or remove scopes that the client requests.

For example, most Micropub servers require clients to obtain the "post" scope in order to create posts. However, some servers may require more granular scope requests, such as "delete" or "post:video". See scope for more details and a list of all currently used values for scope.

Verification

(This section is a stub)

When a Micropub client obtains an access token, it may need to be able to verify the access token is valid and retrieve the URL of the user it belongs to. Micropub endpoints must implement a method that returns basic information about the access token.

Access tokens can be verified by making an empty GET request to the Micropub endpoint with the access token in the header. If the access token is valid, the Micropub endpoint must reply with at least the "me" parameter, and may also return scope, client_id, and expiration date.

Note: This may not be appropriate for the micropub endpoint and may be better handled by the token endpoint.

Form-encoded Microformats Representation

For the simplicity of writing clients and servers, all Micropub endpoints must handle the standard form-encoded format. At a most basic level, you should be able to write an HTML form and set the form action to your own endpoint and use it to post to your site.


Examples of Creating Objects

Indicating the object being created

To indicate the object being created, use a property called "h", (which would never be the name of a property of a microformats object), followed by the name of the microformats object. Examples:

  • h=entry
  • h=card
  • h=event
  • h=cite

h-entry

The following properties may be included in a request to create a new h-entry:

  • name
  • summary
  • content
  • published
  • updated
  • category = tag1, tag2, tag3 (sent as array syntax: &category[]=tag1&category[]=tag2)
  • slug
  • location
    • as a Geo URI, for example geo:45.51533714,-122.646538633
    • as a URL that contains an h-card
    • My micropub client currently has a map to mark the specific location in LatLng values, and a text input for an actual place name. So my client is sending a request of the form "&location=1.23,%40-4.56:An%40Address" Jonnybarnes.net 07:57, 10 June 2014 (PDT)
  • in-reply-to
  • repost-of
  • syndication
    • Pass one or more URLs pointing to places where this entry already exists. Can be used for PESOS implementations.
  • mp-syndicate-to = https://myfavoritesocialnetwork.example/aaronpk, https://archive.org/, etc.
    • This property is slightly different from the others since it is giving a command to the server rather than describing an object, which is why it is prefixed with "mp-".
New Note

Posting a new note with tags, syndicating to myfavoritesocialnetwork:

  • content
  • category
  • mp-syndicate-to
  • published (optional, defaults to "now" if not present. Useful for writing offline and syncing later)
POST /micropub HTTP/1.1
Host: aaronparecki.com
Content-type: application/x-www-form-urlencoded

h=entry
&content=The+%40Jawbone+UP%2C+my+favorite+of+the+%23quantifiedself+trackers%2C+finally+released+their+official+API%21+http%3A%2F%2Fjawbone.com%2Fup%2Fdeveloper%2F
&category[]=jawbone&category[]=quantifiedself&category[]=api
&mp-syndicate-to=https://myfavoritesocialnetwork.example/aaronpk
Minimal Example
POST /micropub HTTP/1.1
Host: example.com
Content-type: application/x-www-form-urlencoded
Authorization: Bearer XXXXXXX

h=entry
&content=Hello+World
curl https://example.com/micropub -d h=entry -d "content=Hello World" -H "Authorization: Bearer XXXXXXX"
New Reply

Posting a new reply, syndicating to myfavoritesocialnetwork

  • content
  • in-reply-to
  • mp-syndicate-to
  • published
POST /post/new HTTP/1.1
Host: aaronparecki.com
Content-type: application/x-www-form-urlencoded

h=entry
&content=%40BarnabyWalters+My+favorite+for+that+use+case+is+Redis.+It%27s+easy+to+set+up+and+use%2C+I+often+use+it+to+move+data+between+apps+written+in+different+languages+too.
&in-reply-to=http://waterpigs.co.uk/notes/4S0LMw/
&mp-syndicate-to=https://myfavoritesocialnetwork.example/aaronpk
New Repost

Posting a new repost, and adding additional tags.

  • repost-of
  • category
POST /micropub HTTP/1.1
Host: aaronparecki.com
Content-type: application/x-www-form-urlencoded

h=entry
&repost-of=http://waterpigs.co.uk/notes/4S0LMw/
&category=realtime
New Article

Posting a new article

  • content
  • name
  • category
  • published
POST /micropub HTTP/1.1
Host: aaronparecki.com
Content-type: application/x-www-form-urlencoded

h=entry
&content=Now+that+I%27ve+been+%5Bhttp%3A%2F%2Faaronparecki.com%2Fevents+creating+a+list+of+events%5D+on+my+site+using+%5Bhttp%3A%2F%2Findiewebcamp.com%2Fp3k+p3k%5D%2C+it+would+be+great+if+I+could+get+a+more+calendar-like+view+of+that+list.+%0A%0ASince+I+live+in+Google+Calendar+every+day+anyway%2C+it+would+be+great+to+use+that+interface+to+browse+my+%23indieweb+events+as+well%21+Since+my+events+page+is+marked+up+with+%5Bhttp%3A%2F%2Fmicroformats.org%2Fwiki%2Fh-event+h-event+microformats%5D%2C+all+it+would+take+is+to+write+an+h-event+to+iCal+converter+script+to+generate+an+iCal+feed+from+my+list+of+events.+Then+I+could+just+subscribe+to+the+iCal+feed+from+within+Google+Calendar.%0A%0A%23%23%23+Bonus%3A+read%2Fwrite+access+to+indieweb+events+via+Google+Calendar%0A%0AEven+better+would+be+to+use+Google+Calendar+to+also+create+events+on+my+site.+Unfortunately+Google+Calendar+doesn%27t+support+CalDAV%2C+so+we+can%27t+do+it+that+way.+%28Of+course+I+could+use+Apple%27s+iCal+to+publish+directly%2C+but+that+also+means+I%27d+have+to+write+some+code+tot+speak+CalDAV%29.+%0A%0AInstead%2C+I+can+create+a+%22write-only%22+calendar+in+Google+Calendar%2C+and+have+p3k+subscribe+to+it.+Any+new+events+in+that+feed+would+be+moved+over+to+the+internal+events+page+and+deleted+from+the+Google+Calendar.
&name=Itching%3A+h-event+to+iCal+converter
&category[]=indieweb&category[]=hevent&category[]=events&category[]=calendar&category[]=p3k
New Bookmark

Posting a new bookmark with name, quote, and tags.

  • bookmark-of
  • name
  • content
  • category
POST /micropub HTTP/1.1
Host: aaronparecki.com
Content-type: application/x-www-form-urlencoded

h=entry
&bookmark-of=https%3A%2F%2Fplus.google.com%2F%2BKartikPrabhu%2Fposts%2FUzKErSbfmHq
&name=To+everyone+who+is+complaining+about+Popular+Science+shutting+down+comments...
&content=%22Why+is+there+this+expectation+that+every+website+should+be+a+forum%3F+No+website+has+any+obligation+to+provide+a+space+for+your+rants.+Use+your+own+space+on+the+web+to+do+that.%22
&category[]=indieweb&category[]=comments


Adding Files

When a Micropub request includes a file, the entire request is sent in the multipart/form-data encoding, and the file is named by content type, either "audio", "video" or "photo". A request may include one or more of these files.

When OwnYourGram makes a Micropub request to post a video, it also sends a photo which is a thumbnail preview of the video.

In PHP, these files are accessible using the $_FILES array:

$_FILES['video']
$_FILES['photo']
$_FILES['audio']

see also: Micropub-brainstorming#Uploading_files_in_separate_requests

Note that there is no practical way to upload a file when the request body is JSON encoded.

h-event

The following properties may be included in a request to create a new h-event:

Posting a new event

  • name
  • summary
  • description
  • start
  • end
  • duration
  • category
  • location
POST /micropub HTTP/1.1
Host: aaronparecki.com
Content-type: application/x-www-form-urlencoded

h=event
&name=IndieWeb Dinner at 21st Amendment
&description=In SF Monday evening? Join @caseorganic and I for an #indieweb dinner at 6pm! (Sorry for the short notice!)
&start=2013-09-30T18:00:00-07:00
&category=indieweb
&location=http://21st-amendment.com/


h-cite

The following properties may be included in a request to create a new h-cite:

(The following list is from microformats.org/wiki/h-cite)

  • name
  • published - date of publication of the work (not the date the h-cite was created)
  • author - URL of an h-card
  • url - a URL to access the cited work
  • content - the content or partial content of the work itself, such as when including a blockquote snippet of a work

Nested Microformat Objects

Whenever possible, nested Microformats objects should be avoided. A better alternative is to reference objects by their URLs. The most common example is including an h-card for a venue, such as checking in to a location or tagging a photo with a person or location. In these cases, it is better to reference the object by URL, creating it first if necessary.

For simple values such as an h-geo property with latitude and longitude, just use a Geo URI such as geo:37.786971,-122.399677

This technique has the advantage of ensuring that each object that is created has its own URL (each piece of data has its own link). This also gives the server an opportunity to handle each entity separately. E.g., rather than creating a duplicate of an existing venue, it may give back a link to one that was already created, possibly even merging in newly received data first.

For more complicated objects, it is better to first create an object on the target site so that it has its own URL, then reference that object's URL in the main request.

For example, creating a checkin post would involve two POST requests:

First create the venue by posting an h-card:

POST /micropub

h=card
&name=Ford+Food+and+Drink
&url=http://www.fordfoodanddrink.com/
&street-address=2505 SE 11th Ave
&locality=Portland
&region=OR
&postal-code=97214
&geo=geo:45.5048473,-122.6549551
&tel=(503) 236-3023

Response:

HTTP/1.1 201 Created
Location: http://example.com/venue/10

Then create the checkin post:

POST /micropub

h=entry
&location=http://example.com/venue/10
&name=Working on Micropub
&category=indieweb

Response:

HTTP/1.1 201 Created
Location: http://example.com/entry/1001
  • This technique has the advantage of ensuring that each object that is created has its own URL (each piece of data has its own link)
  • Also gives the server an opportunity to handle each entity separately. E.g., rather than creating a duplicate of an existing venue, it may give back a link to one that was already created, possibly even merging in newly received data first.

In some cases, it does not make sense for the nested object to have a URL. For example, when posting an h-measure value, there is no reason for the h-measure itself to have a URL, so this is an acceptable case to use the nested microformats object syntax.

For example, creating a new "weight" measurement post as an h-entry with h-measure objects:

h=entry
&weight[type]=h-measure
&weight[properties][num]=155.73
&weight[properties][unit]=lb
&bodyfat[type]=h-measure
&bodyfat[properties][num]=19.83
&bodyfat[properties][unit]=%

If you think you have found a case that requires a nested object, please document it on Micropub-brainstorming and feel free to drop in the IRC channel to discuss it.

Examples

IndieWeb Examples

Examples of IndieWeb sites that support the micropub API (in order of deployment).

Aaron Parecki

Aaron Parecki supports publishing various post types on aaronparecki.com using micropub since 2013-12-25.

  • 2013-12-25 note micropub publishing support added
  • 2013-12-28 pushup micropub publishing support added
  • 2014-02-24 photo micropub publishing support added
  • 2014-09-17 bookmark micropub publishing support added
  • 2014-11-07 repost micropub publishing support added
  • 2014-12-22 like micropub publishing support added

Barnaby Walters

Barnaby Walters posts notes and replies on waterpigs.co.uk (Taproot) since 2014-03-10 using Shrewdness and Taproot as micropub clients

Emma Kuo

Emma Kuo posts notes, replies and photos on notenoughneon.com since 2014-04-28 using Neonblog and OwnYourGram.

Kyle Mahan

Kyle Mahan uses micropub to post photos on his personal site (Red Wind) since 2014-05-17. As of 2015-02-10, he also posts replies and likes using Woodwind as a Micropub client.

Kartik Prabhu

Kartik posts notes on kartikprabhu.com via micropub using Quill since 2014-05-24

Postly

Ben Roberts posts to his Postly site via micropub. Photos are posted using OwnYourGram and Notes, Replies, and Articles are posted using his own Postly Client. Deleting entries via micropub added 2014-09-28.

Jeremy Keith

Jeremy Keith supports posting notes and photos via micropub since 2014-10-21. He shared an example of his PHP source code, minimal micropub endpoint.

Bear

bear supports micropub since 2015-01-01.

  • 2015-01-01 note support added
  • 2015-01-01 article support added

rhiaro

Amy Guy supports micropub since 2015-04-04, used with Quill and Teacup, with various hacks:

  • Supports any post types by passing all metadata in the 'content' param as and inferring post types from it (so all a client needs is a content field).
  • Supports edit over POST via resending content (+ metadata) and the slug of the post to be edited.

Pelle Wessman

Pelle Wessman supports basic micropub publishing of articles on voxpelli.com since 2015-07-10

Shane Hudson

Shane Hudson supports micropub for notes (with geo) only since 2015-07-11. Twitter syndication and photo support are on the to-do list.

Jeena Paradies

Jeena Paradies supports micropub for notes (with syndication and reply-to) only since 2015-07-12. Posting photos works too since 2015-07-24. And now even person tagging for notes and photos since 2015-07-30.

kongaloosh

kongaloosh supports micropub since 2015-04-04, used with Quill and Own Your Gram.

  • Supports any post types by and inferring post types.

Harry Reeder

Harry Reeder supports publishing with micropub since 2015-07-26. Currently note type only, with more on the to-do.

CMS Examples

Micropub has been added to the following CMS software and blog publishing tools for additional server support.

Known

Ben has written a Known plugin that logs in via IndieAuth and publishes content via micropub. It's designed to work so that all indieweb post types - notes etc - are passed to the content plugin registered to handle them. [5]

WordPress

WordPress supports Micropub via Ryan Barrett's wordpress-micropub plugin, including:

Drupal

Stefan Auditor wrote a Drupal module to add a Micropub endpoint to Drupal installs on 2015-05-10. https://github.com/sanduhrs/micropub

Craft

Shane has written a Craft plugin for Micropub. It currently only works with notes and requires some configuration to setup. It has also only been tested with Quill so far, as of 2015-07-11. https://github.com/ShaneHudson/Micropub_Craft

Jekyll

Pelle Wessman has written a self-hosteable service that exposes a Micropub endpoint and then performs the instructions sent to that endpoint by committing Jekyll formatted data to a GitHub repository for the Jekyll site. Modular built and would be possible to extend to support other systems like Jekyll as well. https://github.com/voxpelli/webpage-micropub-to-github

Services Examples

Silo.pub

In April 2015, Kyle Mahan created Feverdream aka silo.pub to provide a Micropub endpoint to create posts on hosted blogs like Tumblr, WordPress.com, Blogger, twitter, Facebook and Flickr

ownyourresponses

Ryan Barrett's ownyourresponses is PESOS as a service for Twitter favorites, retweets, and replies and Instagram likes. It polls your accounts periodically for new activity via the APIs and creates corresponding like, repost, and reply posts on your site via Micropub.

The original motivation is described in PESOS for Bridgy Publish.

Clients

Sites and client applications that publish via micropub. Alphabetically sorted.

Editorial

The iOS text editor Editorial can publish its documents to Micropub through a couple of third party Workflows created by Pelle Wessman. Two for authorizing and deauthorizing with an IndieAuth endpoint and one for the Micropub publishing. Shown in action in this video.

Jonnybarnes.uk

JonnyBarnes post UI is publicly available at https://jonnybarnes.uk/notes/new

Micropublish

Micropublish is Barry Frost's simple Micropub client. Supports Note, Article, Bookmark, Reply, Repost and Like post types. Barry uses this to post all content on his site. Ruby source code is available on GitHub.

micropub-xmpp-bot

In September 2015, Kyle Mahan created micropub-xmpp-bot, an experimental XMPP chat bot for posting notes, replies, likes, and reposts via micropub. Notably, it uses an out-of-band redirect_uri handler that prompts the user to copy/paste their auth code. Give it a shot by XMPP chatting with micropub@kylewm.com. (If it's offline, ping "kylewm" on IRC).

open source: https://github.com/kylewm/micropub-xmpp-bot/

MobilePub

MobilePub is awebapp micropub client app written by Ben Roberts. The app can take and upload photos, video, and audio as well. These features are missing from the new webapp version.

Monocle

Monocle is a reader that supports posting likes and reposts to the user's Micropub endpoint.

Neonblog

Emma's Neonblog post UI creates notes and articles via micropub.

OwnYourCheckin

Based on aaronpk's OwnYourGram, OwnYourCheckin is a tool to reverse-syndicate Foursquare/Swarm checkins with photos to your personal site, using micropub.

OwnYourGram

aaronpk's OwnYourGram is a tool to reverse-syndicate instagram photos to your personal site, using micropub.

  • The signup process contains lots of useful documentation and debugging information to help get new micropub implementations working.

Postly

Ben Roberts' Postly creates notes and articles via micropub and can add syndication links after posting. synditate-to links are passed as a php readable array field not a comma separated list. Postly can also edit posts when passing mp-action=edit Publicly Available UI

PushupCounter

aaronpk's PushupCounter-iOS is an iOS client for publishing exercise data.

Quill

Quill is a reference Micropub client developed by Aaron Parecki, you can use it to post notes, articles, bookmarks and likes to your site.

  • The signup process walks you through configuring your website to accept Micropub requests from apps like this.

Shrewdness

Shrewdness - indieweb reader

Taproot

Barnaby's Taproot publishes notes via micropub. The post UI is publicly accessible, and you can use it to make posts on your own website. As of 2014-06-12 it’s also marked up with h-product and h-x-app markup so that authorization UIs can provide a better experience whilst authorizing, without having to pre-register apps and upload logos

Teacup

Teacup is a Micropub client for posting various types of food posts.

unmpc

unmpc - an experiment by elf Pavlik which implements Micropub client +reader as Unhosted web app (HTML5 running fully in a web browser - noBackend)

Woodwind

Woodwind has optional support for posting replies and likes via Micropub. Includes toggles for syndicate-to endpoints as of 2015-02-10.

Libraries

Open source libraries & implementations used to support micropub on the client app side and on the API endpoint side on the server:

Issues

Please use the Github repo for issues and discussion related to the spec.

For issues that have been discussed and are ready to consider for inclusion in the spec, use the Micropub-brainstorming page to collect examples and iterate on the ideas.

See Also

Personal tools
Namespaces
Variants
Actions
Recent & Upcoming
Resources
Toolbox