Micropub Express
Provides a Micropub route for Express 4.x
Requirements
Node.js requirement is set in package.json
(Use eg. installed-check to validate that it complies with your requirements)
Installation
npm install micropub-express --save
Current status
Early alpha
Supported:
- Creation of content based items and creation of likes
The rest of the CRUD-operations + other more complex operations are yet to be built and the API might change to adopt to the requirements of those. Versioning will stick to Semantic Versioning to clearly communicate such breaking changes.
Usage
var micropub = ; // Attach the micropub endpoint to "/micropub" or wherever else you wantapp;
Advanced Usage
var express = ;var micropub = ; var app = ; // Do some Express magic to support multiple Micropub endpoints in the same applicationapp; app; // Start the Express server on a port, like port 3000!app;
Options
- tokenReference – required – either an object with two keys,
me
andendpoint
, or a function that receives the request object and returns an object with those two keys. Theme
key signify what identity it is that's expected for a succesful authorization and theendpoint
key indicates what endpoint the token should be verified with. Can also be or return an array of multiple references. - handler – required – the function that will be called with the handled micropub document and the request object. It's this functions responsibility to actually act on the received data and do something with it. Should return a
Promise
resolving to an object with aurl
key containing the url of the created item to indicate success. If thePromise
is rejected or theurl
key is missing or falsy in the resolvedPromise
, then a400
error will be returned to indicate failure. - userAgent – recommended – a user-agent string like
your-app-name/1.2.3 (http://app.example.com/)
that gets prepended to the user-agent ofmicropub-express
itself when verifying received tokens against an endpoint - queryHandler – optional – a function that will be called whenever a
?q=
query is made to the Micropub endpoint. It's this functions responsibility to execute the query and respond with the relevant data. Should return aPromise
resolving to an object containing the query result. Keys on the object should not include any[]
, those will be added in the encoded result where relevant. If thePromise
resolves to something falsy, then a400
error will be returned to indicate that the query type is unsupported. If thePromise
is rejected, then a400
error will be returned to indicate failure. - logger – optional – a bunyan compatible logger, like bunyan itself or some other module. Defaults to bunyan-duckling which logs with
console.log()
andconsole.error()
micropubDocument
Format of The format closely matches the JSON-representation of Micropub.
It contains three top level keys:
- type – an array containing the type that is that's going to be created. Eg.
['h-entry']
- properties – an object containing all of the microformat properties of the document as arrays containing strings. Eg.
content: ['foobar']
- mp – an object containing all of the micropub directives as arrays containing string. Eg.
'syndicate-to': ['http://twitter.com/example']
for an'mp-syndicate-to'
directive. - files – an object that can contain three keys,
audio
,video
,photo
, which in turn contains arrays of objects with afilename
and abuffer
key with the name and content of the files.
Full example:
type: 'h-entry' properties: content: 'hello world' mp: 'syndicate-to': 'http://twitter.com/example' files: photo: filename: 'example.jpg' buffer: // A Node.js buffer with the content of the file.
Other useful modules
- format-microformat – a module that takes a
micropubDocument
as its input and then formats filenames, URL:s and file content from that data so one gets some standard data which one then can publish elsewhere – like to a Jekyll blog or something. - github-publish – a module that takes a filename and content and publishes that to a GitHub repository. A useful place to send the formatted data that comes out of
format-microformat
if one wants to add it to a GitHub hosted Jekyll blog of some kind, like eg. GitHub Pages.