@aspida/resas
v0.4.1
Published
resas API for aspida
Downloads
22
Readme
RESAS-API | Cabinet Office,Government Of Japan.
Installation
$ npm install typescript ts-node @types/node axios @aspida/resas
Usage
index.ts
Because there is mock data, this script works without registering API key.
import axios from "axios"
import api, { mock, ApiTypes } from "@aspida/resas"
if (process.env.NODE_ENV === "production") {
// Get API key here: https://opendata.resas-portal.go.jp/form.html
axios.defaults.headers.common["X-API-KEY"] = process.env.API_KEY
} else {
mock()
}
;(async () => {
const prefCode = ApiTypes.PrefCode.Hokkaido
const cities = await api().v1.cities.$get({ params: { prefCode } })
const { cityCode } = cities.result.filter(city => city.cityName === "札幌市")[0]
const population = await api().v1.population.composition.perYear.$get({
params: { prefCode, cityCode }
})
console.log(population.result)
})()
package.json
{
"scripts": {
"start": "ts-node index"
}
}
Run
$ npm start
Result
{ boundaryYear: 2015,
data:
[ { label: '総人口', data: [Array] },
{ label: '年少人口', data: [Array] },
{ label: '生産年齢人口', data: [Array] },
{ label: '老年人口', data: [Array] } ] }