Raul Chedrese

Adding Support for MarsEdit to a Blog

I recently decided to start blogging but ran into trouble picking a blogging platform. I only had a few requirements. The blog needed to be fast, simple, and support posting from MarsEdit. Unfortunately I couldn’t find anything that ticked all of those boxes so I built my own! Here are the steps I took to add support for MarsEdit to my blog.

Choosing an API

MarsEdit supports multiple APIs for communicating with your blog so you’ll need to choose which to implement. The best choice seems to be the MetaWeblog API. It supports all of the features you’ll need and is relatively well documented.

Debugging

The standards involved here are quite old and often not completely documented. To save time and avoid frustration you’ll want to make sure you can easily see the requests going between MarsEdit and your server. MarsEdit has a handy built in “Network Log” for exactly this purpose. You can access it in the menu via Window > Network Log. Proxyman is another great option. It has a bit of a learning curve but is powerful and great to use once you poke around a bit.

Implementing MetaWeblog

The MetaWeblog API is follow the XML-RPC specification. This means that the requests will all be in XML and formatted according to the rules of XML-RPC. You should be able to find a package for most programming languages that handles parsing the XML-RPC format. This will free you from needing to deal with the XML directly. XML-RPC works by making an HTTP POST request to a single endpoint. You’ll need to implement that endpoint and have it check the methodName in each request to identify what action needs to be taken. Here is an example of a MetaWeblog request payload.
<methodCall>
	<methodName>metaWeblog.getRecentPosts</methodName>
	<params>
		<param>
			<value><string>rched</string></value>
			</param>
		<param>
			<value><string>raul</string></value>
			</param>
		<param>
			<value><string>blog_password</string></value>
			</param>
		<param>
			<value><int>50</int></value>
		</param>
	</params>
</methodCall>
Unfortunately the MetaWeblog XML format relies on ordered parameters and each method has a different set of parameters. This means you need to know which parameter is supposed to be in each position to properly parse them. You can find the parameters listed in order on the Wordpress MetaWeblog docs. You’ll need to implement support for at least these methods:

Authentication

MarsEdit supports two options for authenticating with your blog API.
  1. HTTP Basic Authentication. This is what I chose to use for this blog. It’s a well supported web standard with tooling easily available. Just make sure your API returns the WWW-Authenticate header when it is accessed without the Authorization header as described here. If you don’t do this MarsEdit will not send the Authorization header even if a password is set in the app.
  2. MetaWeblog based authentication. All of the MetaWeblog request methods accept a username and password parameter. You can grab those from the request the same way you grab other parameters and check them against your stored passwords.
You can also use both of these if you like.

Automatic Setup

MarsEdit has a cool feature that allows it to automatically configure your blog in MarsEdit by simply providing the url to your blog. This feature relies on your blog providing a RSD file that describes the APIs your blog supports. An example RSD file.
<?xml version="1.0" ?> 
<rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd" >
    <service>
        <engineName>Leaflet Feed</engineName> 
        <engineLink>https://leafletfeed.com/</engineLink>
        <homePageLink>https://rched.com/</homePageLink>
        <apis>
                <api name="MetaWeblog" preferred="true" apiLink="https://rched.com/meta-weblog" blogID="rched" />
        </apis>
    </service>
</rsd>
Once this you’ve made this file publicly accessible on your server you’ll need to make sure MarsEdit can find it from your homepage. You can do this by adding a link tag to your blog homepage.
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://rched.com/rsd" />