Git Product home page Git Product logo

jp-zip-lookup's Introduction

Japan ZIP Code Lookup

This is a simple REST-based webservice that allows users to lookup Japanese ZIP codes and get the address for it.

Dataset

The dataset used is the official 住所の郵便番号(CSV形式) data provided by Japan Post. The service uses the 読み仮名データの促音・拗音を小書きで表記するもの version of the data.

Build Instructions

Requirements

You will need the following software/tools installed on your system

Building and running

Run cargo build --release to build a release build of the service.

Run cargo run to run a debug build of the service.

Then try one of the following curl examples:

# general healthcheck endpoint
curl -s http://localhost:8900/healthcheck | jq
{
  "message": "ok"
}

# get a list of postcodes
curl -s http://localhost:8900/postcodes | jq
[
  "0010000",
  "0010010",
  "0010011",
  "0010012",
  "0010013",
  "0010014",
  "0010015",
  ...
]

# get a list of cities in "postcode" (e.g. 1130034)
# you can use incomplete postcodes, e.g. only the first 3 digits
curl -s http://localhost:8900/postcodes/:postcode | jq

# example for 113-0034
curl -s http://localhost:8900/postcodes/1130034 | jq
[
  {
    "zipCode": "1130034",
    "muncipalitiesKanji": "文京区",
    "muncipalitiesKana": "ブンキョウク",
    "muncipalitiesKanaFull": "ブンキョウク",
    "muncipalitiesHiragana": "ぶんきょうく",
    "muncipalitiesRomaji": "bunkyouku",
    "townKanji": "湯島",
    "townKana": "ユシマ",
    "townKanaFull": "ユシマ",
    "townHiragana": "ゆしま",
    "townRomaji": "yushima"
  },
  ...
]

# get a list of prefectures
curl -s http://localhost:8900/prefectures | jq
[
  {
    "prefCode": "01",
    "halfWidthKana": "ホッカイドウ",
    "fullWidthKana": "ホッカイドウ",
    "hiragana": "ほっかいどう",
    "pref": "北海道",
    "romaji": "hokkaidou"
  },
  ...
]

# get a list of cities for a prefecture by providing the prefecture code
curl -s http://localhost:8900/prefectures/:prefecture_code/cities | jq
# example for Hokkaido
curl -s http://localhost:8900/prefectures/01/cities | jq
[
  {
    "govCode": "01101",
    "zipCode": "0600001",
    "halfWidthKana": "キタ1ジョウニシ(1-19チョウメ)",
    "fullWidthKana": "キタ1ジョウニシ(1-19チョウメ)",
    "hiragana": "きた1じょうにし(1ー19ちょうめ)",
    "city": "北一条西(1~19丁目)",
    "romaji": "kita1jounishi(1-19choume)"
  },
  ...
]

Database

The database must be up and running for the service to work.

The following environment variables are read to connect to the database:

# showing default values here
JPZIP_DB_HOST="localhost"
JPZIP_DB_PORT=5432
JPZIP_DB_NAME="jpzip"
JPZIP_DB_USER="jpzip"
JPZIP_DB_PASSWORD="jpzip"

The service can automatically download the data and import it into the dabase, but the schema must exists prior to that.

You can use a .env environment file to set those variables. See .env.example for an example.

Docker

You can use Docker to run the PostgreSQL database service. Check README.md for details.

Copyright

Copyright (c) 2022, 2023 by Daniel Kurashige-Gollub [email protected]

License

MIT 2.0

jp-zip-lookup's People

Contributors

dgollub avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.