Create a gist now

Instantly share code, notes, and snippets.

@shimizu /README.md
Last active Nov 21, 2016

What would you like to do?
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