6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

HEROKU APIをjQuery.ajaxで叩く

Last updated at Posted at 2015-12-12

はじめに

herokuのweb apiであるplatform apiを、jQuery.ajaxから実行する方法についてまとめました。

前提条件

  • herokuのアカウントを持っている
  • herokuの管理画面からAPI KEYを控える

実際のコード

/**
 * herokuアプリを再起動する
 *
 * @param{String} apiKey APIキー
 * @param{String} appName heorkuアプリ名
 */
function restartHeroku(apiKey, appName) {
    $.ajax('https://api.heroku.com/apps/'+appName+'/dynos',{
        headers:{
            Accept: 'application/vnd.heroku+json; version=3',
            Authorization: 'Bearer '+apiKey
        },
        global:false,
        method: 'DELETE'
    }).then(function(){
        console.log('success');
    }).fail(function(){
        console.log('error');
    });
}

実行したAPIの仕様はこちら
https://devcenter.heroku.com/articles/platform-api-reference#dyno-restart-all

作ってみたアプリについて

上記コードは趣味で作ったheroku再起動アプリのものです。cordovaを使って作ってます。よろしければ、参考にしてあげてください。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?