@aspida/resas
TypeScript icon, indicating that this package has built-in type declarations

0.4.1 • Public • Published
RESAS-API for aspida

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] } ] }

Dependents (0)

Package Sidebar

Install

npm i @aspida/resas

Weekly Downloads

6

Version

0.4.1

License

MIT

Unpacked Size

522 kB

Total Files

135

Last publish

Collaborators

  • m-mitsuhide
  • solufa