Skip to content

Instantly share code, notes, and snippets.

@shimizu
Last active November 21, 2016 08:36
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 shimizu/add64a8d254038f500911ab01cf05b6d to your computer and use it in GitHub Desktop.
Save shimizu/add64a8d254038f500911ab01cf05b6d to your computer and use it in GitHub Desktop.
RESAS API CLI

概要

RESAS API からJSONを取得します。

インストール

npm install

req.js の "APIKEY"変数にAPIキーを入力する

使い方

node req.js "https://opendata.resas-portal.go.jp/api/v1-rc.1/prefectures" > result.json
{
"name": "resas_api",
"version": "1.0.0",
"description": "",
"main": "req.js",
"dependencies": {
"request": "^2.76.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
const request = require('request');
const APIKEY = "RESAS API KEY" //APIキーに書き換えてください
if (process.argv.length < 3) {
console.log("引数にURLを指定してください");
process.exit();
}
const url = process.argv[2]
const headers = {
'Content-Type':'application/json',
'X-API-KEY': APIKEY
}
const options = {
url: url,
method: 'GET',
headers: headers,
json: true,
}
request(options, function (error, response, body) {
if (error) throw new Error(error)
console.log(body)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment