API & Content Preservation

At the Pastry Box, we don't take the question of content preservation and consumption lightly. You will find in this document explanations about our API and a pastrybox node module.

The purpose of these features is to decentralize content and help preserve it (read more).

API

Introduction

All API access is over HTTPS. The API supports CORS for XHR. The API doesn't require any json encoding on your part, and doesn't need out-of-the-ordinary Content-Type either. The public API of the Pastry Box Project is fairly simple and currently consists in one endpoint.

The Consume Endpoint

GET https://the-pastry-box-project.net/api/v1/consume/:content

Parameters

contentstringRequired. The type of content you want to consume.

Note: only the thoughts value is accepted for the content parameter for now.

Example

Optional parameters

daystringThis parameter lets you retrieve the thought published on a specific. Expected format is dd-mm-yyyy.
previousstringThis parameter works with the day param. It lets you retrieve n thoughts before the specified day.
nextstringThis parameter works with the day param. It lets you retrieve n thoughts after the specified day.
from & tostringThese parameters let you retrieve thoughts published between two dates. Format dd-mm-yyyy
bakerstringThis parameter lets you retrieve the thoughts of a specific baker. Use a “slugified” version of the baker's name. E.g. "lea-verou".
formatstringThis parameter lets you tell the API how it should format the thoughts it returns. Values: json (default), html, markdown.

Examples

  • Click this link to get the thought published on 22-10-2013.

  • Click this link to get the thought published on 22-06-2012 and the 5 previous thoughts in an HTML format.

  • Click this link to get the thought published on 01-01-2013 and the two following thoughts in an HTML format.

  • Click this link to get the thoughts published between 22-10-2012 and 22-11-2012.

  • Click this link to get the thoughts published by @LeaVerou

  • The JSON format will include lots of useful information in addition to the thoughts returned.

  • The HTML format returns the thoughts in the form of a web page. You can check the template used in this scenario on Github. It's the same template used to create the standalone files of our content stored on Github.

  • The Markdown format strips all HTML tags and returns a markdown version of the requested thoughts. This parameter is used by the node-pastrybox module to display content in the console.

The node-pastrybox module

View on Github

This package lets you read directly in the console and print the texts published on The Pastry Box Project.

Install

$ npm install -g node-pastrybox

Arguments & Options

Read the most recent text

$ pastrybox today

Returns the text published today.

Read a specific text

$ pastrybox day 21-10-2012

Returns the text published on October the 21st, 2012.

Read texts based on a range

$ pastrybox from 21-10-2012 to 21-11-2012

Returns the texts published from October the 21st to November the 21st, 2012.

Read n previous texts

$ pastrybox day 21-10-2012 previous 7

Returns the text published on October the 21st, and the seven texts published right before that date.

Read n next texts

$ pastrybox day 21-10-2012 next 7

Returns the text published on October the 21st, and the seven texts published right after that date.

Read texts from a specific author

$ pastrybox baker lea-verou

Returns the texts published by @LeaVerou.

Print

Any response can be turned into a PDF file. Just add the print argument to your command.

$ pastrybox today print
$ pastrybox day 21-10-2012 print
$ pastrybox from 21-10-2012 to 21-11-2012 print
$ pastrybox baker erin-kissane print
...

To print all the content published on the The Pastry Box, just do:

$ pastrybox print

To extract our database in a JSON format, just do:

$ pastrybox

PDF files are always created in the current working directory.

File names

By default, a .pdf file is named based on the following scheme: pastrybox-$timestamp.pdf

You can override this behavior by specifying your own file name:

$ pastrybox today print file "today.pdf"
$ pastrybox day 21-10-2012 print file super-thought.pdf
$ pastrybox from 21-10-2012 to 21-11-2012 print file "cool-stuff"
...

As you can see, you can ommit the .pdf file extension. It will automatically be added. Double quotes are also optional.

Archives

$ pastrybox archives $year

Specify a $year, and you will download all the content published on the Pastry Box for that year on your computer (in the current working directory, to be more specific). The result of archiving a year will look exactly like the archives we have on GitHub.

Any suggestions about what should be added to this module? Check the node-pastrybox repo on Github.