Services / Json API

The primary API for programmatically accessing the Friendpaste is a REST API. All data sent to the server should be encoded in JSON.

Get a paste

To retrieve a paste, simply perform a GET operation on the paste url.

GET /some_paste_id HTTP/1.0
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT

Here is the server response.

HTTP/1.1 201 OK
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{
 'id': 'some_paste_id'
 'revid': 'some_revision_id',
 'title': 'title of paste',
 'snippet': 'paste content',
 'language': 'text'
}

Create a paste

To create a paste, perform a POST operation at http://www.friendpaste.com/ .

The following is an example HTTP POST. It will cause the Friendpaste server to generate a new paste ID and save the content with it.

POST / HTTP/1.0
Content-Length: 245
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json

{
  "title":"I like to paste stuff",
  "snippet":"My own paste",
  "language":"text"
}
    

Here is the server's response.

HTTP/1.1 201 OK
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{"ok": true, "id": "some_paste_id", "revid": "paste_revision_id", "url": "http://friendpaste.com/some_paste_id"}
    

If the paste is created the server return you a JSON object in which you get the id of created paste and the direct url to the paste.

If any error happend whil pasting, here is the server response.

HTTP/1.1 201 OK
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{"ok": false, "reason": "error message"}
    

Update a paste

To update a paste, perform a PUT operation at http://www.friendpaste.com/some_paste_id .

The following is an example HTTP PUT. It will cause the Friendpaste server to generate a new revision of the paste and update current content with it.

PUT /some_paste_id HTTP/1.0
Content-Length: 245
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json

{
  "title":"I like to paste stuff",
  "snippet":"My own paste updated",
  "language":"text"
}
    

Here is the server's response.

HTTP/1.1 201 OK
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{"ok": true, "id": "some_paste_id", "revid": "new_revision_id", "url": "http://friendpaste.com/some_paste_id"}
    

If the paste is created the server return you a JSON object in which you get the id of created paste and the direct url to the paste.

If any error happend whil pasting, here is the server response.

HTTP/1.1 201 OK
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{"ok": false, "reason": "error message"}
    

Get revisions

To retrieve all revisions of a paste, simply perform a GET operation on http://friendpaste.com/some_paste_id/revisions.

GET /some_paste_id/revisions HTTP/1.0
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT

Here is the server response.

HTTP/1.1 200 OK
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json
Connection: close


[{"updated": "2008-05-05T14:04:22Z", "language": "text", "parent": "XsM9Yxdp", "title": "", "_rev": "1229081332", "created": "2008-05-05T14:04:22Z", "revid": "c26e9c60007a", "snippet": "sdsd", "_id": "XsM9Yxdp", "type": "snippet"}, {"updated": "2008-05-05T14:04:22Z", "parent": "XsM9Yxdp", "language": "text", "title": "", "_rev": "1180921947", "created": "2008-05-05T14:04:22Z", "revid": "c26e9c60007a", "snippet": "sdsd", "_id": "263f1c96da8002395b0e70bce0ab254e", "type": "revision"}]

Get a changeset

To retrieve a changeset, simply perform a GET operation on http://friendpaste.com/some_paste_id/changeset?rev=some_rev_id. Changeset are in unidiff format

GET /some_paste_id/changeset?rev=some_rev_id HTTP/1.0
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT

Here is the server response.

HTTP/1.1 200 OK
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{
 'id': 'some_paste_id'
 'rev': 'some_revision_id',
 'changeset': 'changeset in unidiff format'
}

Get all languages

To retrieve list of all languages supported by Friendpaste, simply perform a GET operation on http://friendpaste.com/all_languages url.

GET /_all_languages HTTP/1.0
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT

Here is the server response.

HTTP/1.1 200 OK
Date: Tue, 29 Apr 2008 05:39:28 +0000GMT
Content-Type: application/json
Connection: close

{"text": "Text only", "genshi": "Genshi", "html+myghty": "HTML+Myghty", "trac-wiki": "MoinMoin/Trac Wiki markup", "xml": "XML", "css+mako": "CSS+Mako", "erlang": "Erlang", "python": "Python", "js+genshitext": "JavaScript+Genshi Text", "bat": "Batchfile", "myghty": "Myghty", "d": "D", "js+erb": "JavaScript+Ruby", "squidconf": "SquidConf", "befunge": "Befunge", "apacheconf": "ApacheConf", "csharp": "C#", "tex": "TeX", "llvm": "LLVM", "html+django": "HTML+Django/Jinja", "xml+django": "XML+Django/Jinja", "delphi": "Delphi", "js+smarty": "JavaScript+Smarty", "c-objdump": "c-objdump", "lua": "Lua", "redcode": "Redcode", "rb": "Ruby", "irc": "IRC logs", "html+smarty": "HTML+Smarty", "js": "JavaScript", "bash": "Bash", "c": "C", "vb.net": "VB.net", "ocaml": "OCaml", "genshitext": "Genshi Text", "xml+myghty": "XML+Myghty", "pot": "Gettext Catalog", "smarty": "Smarty", "vim": "VimL", "haskell": "Haskell", "diff": "Diff", "js+django": "JavaScript+Django/Jinja", "rbcon": "Ruby irb session", "pycon": "Python console session", "java": "Java", "js+mako": "JavaScript+Mako", "d-objdump": "d-objdump", "perl": "Perl", "common-lisp": "Common Lisp", "scheme": "Scheme", "rhtml": "RHTML", "html+php": "HTML+PHP", "css+genshitext": "CSS+Genshi Text", "xml+mako": "XML+Mako", "js+php": "JavaScript+PHP", "pytb": "Python Traceback", "gas": "GAS", "rst": "reStructuredText", "cpp-objdump": "cpp-objdump", "xml+smarty": "XML+Smarty", "groff": "Groff", "bbcode": "BBCode", "mysql": "MySQL", "objective-c": "Objective-C", "xml+erb": "XML+Ruby", "erb": "ERB", "css+smarty": "CSS+Smarty", "control": "Debian Control file", "css+erb": "CSS+Ruby", "raw": "Raw token data", "as": "ActionScript", "brainfuck": "Brainfuck", "ini": "INI", "mupad": "MuPAD", "django": "Django/Jinja", "css+myghty": "CSS+Myghty", "mako": "Mako", "make": "Makefile", "minid": "MiniD", "css+django": "CSS+Django/Jinja", "sourceslist": "Debian Sourcelist", "html": "HTML", "css+php": "CSS+PHP", "css": "CSS", "html+mako": "HTML+Mako", "objdump": "objdump", "boo": "Boo", "jsp": "Java Server Page", "sql": "SQL", "php": "PHP", "dylan": "DylanLexer", "xml+php": "XML+PHP", "js+myghty": "JavaScript+Myghty", "lhs": "Literate Haskell", "cpp": "C++", "html+genshi": "HTML+Genshi", "moocode": "MOOCode"}