Fun with Micropub

Last night (while waiting to watch the season 3 finale of Westworld), I wrote a Python script to post to my blog from iOS.

Many have done this before, so I found many examples online to get me started. What surprised me was just how simple the Micropub API makes it to post.

Here’s the basic example in Python:

import requests

response = requests.post(
	url=endpoint_url,
	headers={
		"Authorization": “Bearer “ + api_token,
		"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
	},
	data={
		"h": "entry", 
		"content": text_of_post
	}, 
)

And in Swift (if you’ll allow the Alamofire dependency):

import Alamofire

AF.request(
    endpointURL,
    method: .post,
    parameters: [
        "h": "entry",
        "content": textOfPost
    ],
    encoding: URLEncoding.queryString,
    headers: [
        "Authorization": "Bearer \(apiToken)"
    ]
)

Something so simple but powerful promotes creativity, and it gives me The Itch to make something.

Is there an iOS app publish to a Micropub endpoint from a share extension? A search for “micropub” on the App Store would indicate ‘no’. But how difficult would it be to make this? Afterall, the difficult code is already written above.

Something for me to think about…

Andrew Cope @cope