0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Node.js 郵便番号検索API

Posted at

图片.png

yubin.mjs
const zipcode = "1000001"; // 東京都千代田区千代田
const url = `https://zipcloud.ibsnet.co.jp/api/search?zipcode=${zipcode}`;

try {
  const res = await fetch(url);
  if (!res.ok) {
    throw new Error(`HTTPエラー: ${res.status}`);
  }

  const data = await res.json();

  if (data.results) {
    const address = data.results[0];
    console.log(`〒${zipcode}`);
    console.log(`${address.address1} ${address.address2} ${address.address3}`);
  } else {
    console.log(`該当する住所が見つかりません(status: ${data.status})`);
  }

} catch (err) {
  console.error("エラー:", err);
}

图片.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?