Skip to content

Instantly share code, notes, and snippets.

@aaronpk aaronpk/micropub-json.md
Last active Aug 29, 2015

Embed
What would you like to do?

Creating a Post

Creating a post, specifying properties from the microformats2 vocab. The type and properties map to the output of the Microformats 2 parsed result.

Form-encoded requests have a property h=* which specifies the type of object being created. All other properties are considered properties of the object being created.

h=entry&
content=hello+moon&
category[]=indieweb&
category[]=micropub

When submitting a request in JSON format, simply send the JSON-encoded representation of the Microformats2 object you are creating.

{
  "type": ["h-entry"],
  "properties": {
    "content": ["hello moon"],
    "category": ["indieweb","micropub"]
  }
}

Editing a Post

Because of the nuances of modifying specific values in properties, these requests do not have a "simple" form-encoded representation, and must use nested properties with array notation. These form-encoded requests are the same structure as the JSON version, but serialized as form-encoded instead.

Replacing all values of a property

Updating a specific property of a post, replacing all values of the property. If the property does not exist already, it is created.

mp-action=edit
&url=http://example.com/post/1
&update[properties][content]=hello+moon
{
  "mp-action": "edit",
  "url": "http://example.com/post/1",
  "update": {
    "properties": {
      "content": ["hello moon"]
    }
  }
}

Adding a value to a property

Adding a value. If there are any existing values for this property, they are not changed, the new values are added. If the property does not exist already, it is created.

mp-action=edit
&url=http://example.com/post/1
&add[properties][category][]=indieweb
&add[properties][category][]=foo
{
  "mp-action": "edit",
  "url": "http://example.com/post/1",
  "add": {
    "properties": {
      "category": ["indieweb","foo"]
    }
  }
}

Removing a value from a property

Removing a value. This removes just the "indieweb" value from the "category" property, leaving all other values. If no values remain, the property is removed.

mp-action=edit
&url=http://example.com/post/1
&delete[properties][category]=indieweb
{
  "mp-action": "edit',
  "url": "http://example.com/post/1",
  "delete": {
    "properties": {
      "category": ["indieweb"]
    }
  }
}

Removing a property

mp-action=edit
&url=http://example.com/post/1
&delete[properties]=indieweb
{
  "mp-action": "edit",
  "url": "http://example.com/post/1",
  "delete": {
    "properties": ["category"]
  }
}

Deleting a post

mp-action=delete
&url=http://example.com/post/1
{
  "mp-action": "delete",
  "url": "http://example.com/post/1"
}

Posting HTML Content

h=entry&
content[html]=<b>hello+moon</b>&
content[value]=hello+moon
{
  "type": ["h-entry"],
  "properties": {
    "content": [{
      "html": "<b>hello moon</b>",
      "value": "hello moon"
    }]
  }
}

Other Post Examples

Posting a "like"

h=entry&
like-of=http://example.com/thing-being-liked
{
  "type": ["h-entry"],
  "properties": {
    "like-of": ["http://example.com/thing-being-liked"]
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.