Skip to content

Instantly share code, notes, and snippets.

@STRd6
Created June 13, 2016 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save STRd6/21e346b5f55d1a45c1832f01ef94d8f6 to your computer and use it in GitHub Desktop.
Save STRd6/21e346b5f55d1a45c1832f01ef94d8f6 to your computer and use it in GitHub Desktop.
Make requests to the Heroku API from the browser. Note accept and authorization headers.
APIGenerator = require "./api_generator"
{extend} = require "../source/util"
module.exports = (ajax) ->
requester = (path, options={}) ->
options = extend
url: path
method: "GET"
dataType: "json"
contentType: "application/json; charset=utf-8"
withCredentials: false
headers:
"Accept": "application/vnd.heroku+json; version=3"
"Authorization": "Bearer #{API_KEY}"
, options
ajax(options)
{get, put, patch, post} = api = APIGenerator("https://api.heroku.com", requester)
return api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment