Skip to content

Navigation Menu

Sign up
Raynes edited this page Jan 5, 2012 · 25 revisions

Introduction

RefHeap has a simple API. The API is token-based and also works without authentication (for now -- future API methods may require authentication). To get an API token, create an account on RefHeap and go to the API page. You can view/generate API tokens there.

All of the API methods return JSON. The API tries to return useful status codes. The status codes that can possibly be returned are 422, 404, 201, 204, 400, and 200.

All API methods except for fetching single pastes can take the following parameters:

  • username
  • token

Methods

POST /api/paste

  • private: Optional. Either "true" or "false". Defaults to "false".
  • language: Optional. A string of which language to use for the paste. If this is not provided or the language is unrecognizable, the API defaults to "Plain Text". The language must be exactly the same as how it is listed in the dropdown on RefHeap. If the language is "Nginx Configuration" then that is exactly how it must appear when passed to the API.
  • contents: Required. A string of text that will be the body of the paste. This cannot be empty.

Create a new paste.

If a username and token is provided then the paste will be associated with that account. Otherwise, it will be anonymous.

Here is an example using Clojure and clj-http:

user=> (clj-http.client/post "http://refheap.com/api/paste"
 {:form-params {:contents "i like foo" :username "Raynes"
 :token "000000-00000-000-0000000-0000"
 :private true
 :language "IRC Logs"}})
{:status 200,
 :cookies
 {"ring-session"
 {:path "/",
 :version 0,
 :discard true,
 :value "69f1008e-4c04-4366-880f-7a868a48f5f6"}},
 :headers
 {"server" "Jetty(6.1.25)",
 "content-type" "application/json; charset=ISO-8859-1",
 "date" "Thu, 05 Jan 2012 04:18:03 GMT",
 "connection" "close"},
 :body "{\"lines\":1,\"date\":\"2012-01-05T04:18:03.473Z\",\"paste-id\":\"4f05247bd6c4d4f67f6cd123\",\"language\":\"Plain Text\",\"private\":true,\"url\":\"http://refheap.com/paste/4f05247bd6c4d4f67f6cd123\",\"user\":\"raynes\",\"contents\":\"i like foo\"}"}

GET /api/paste/:id

  • id: Required. The id of the paste you want to fetch.

Fetch a paste.

Example using Clojure and clj-http:

user=> (clj-http.client/get "http://refheap.com/api/paste/52")
{:cookies
 {"ring-session"
 {:discard true,
 :path "/",
 :value "a0949bbd-665f-4add-86ca-25f3f69eda4a",
 :version 0}},
 :status 200,
 :headers
 {"date" "Thu, 05 Jan 2012 20:00:02 GMT",
 "content-type" "application/json; charset=ISO-8859-1",
 "connection" "close",
 "server" "Jetty(6.1.25)"},
 :body
 "{\"lines\":1,\"date\":\"2012-01-05T04:14:56.995Z\",\"paste-id\":\"52\",\"language\":\"Plain Text\",\"private\":false,\"url\":\"http://refheap.com/paste/52\",\"user\":null,\"contents\":\"i like foo\"}"}

POST /api/paste/id

Parameters are the same as for creating pastes except that, if any given parameter is not provided, the default is what was in the old paste.

Edit pastes.

You have to be authenticated in order to edit a paste.

Example using Clojure and clj-http:

user=> (clj-http.client/post "http://refheap.com/api/paste/4f05fb90d6c4670e22a5cce2" 
 {:form-params {:username "Raynes" 
 :token "000000-00000-000-0000000-0000" 
 :contents "(+ 5 5)" 
 :language "Clojure" 
 :private false}})
{:status 200,
 :cookies
 {"ring-session"
 {:path "/",
 :version 0,
 :discard true,
 :value "998c3de2-638e-4b73-92fd-848cbeb9bd89"}},
 :headers
 {"server" "Jetty(6.1.25)",
 "content-type" "application/json; charset=ISO-8859-1",
 "date" "Thu, 05 Jan 2012 19:42:37 GMT",
 "connection" "close"},
 :body "{\"lines\":1,\"date\":\"2012-01-05T19:35:43.126Z\",\"paste-id\":\"59\",\"language\":\"Clojure\",\"private\":false,\"url\":\"http://refheap.com/paste/59\",\"user\":\"raynes\",\"contents\":\"(+ 5 5)\"}"}

DELETE /api/paste/:id

  • id: Required. The paste id.

Delete a paste. You must be the owner of the paste in order to delete it.

Example using Clojure and clj-http:

user=> (clj-http.client/delete "http://refheap.com/api/paste/59" 
 {:query-params {:username "Raynes" 
 :token "000000-00000-000-0000000-0000"}})
 
{:status 204, :cookies {"ring-session"
 {:path "/",
 :version 0,
 :discard true,
 :value "e3e5e6bc-9ddd-4b14-9a06-4bc08a70ff09"}},
 :headers
 {"server" "Jetty(6.1.25)",
 "date" "Thu, 05 Jan 2012 19:43:52 GMT",
 "connection" "close"},
 :body nil}

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /