Public API Documentation for Zippopotam.us

If you're looking for a simple and easy-to-use API for retrieving postal code information from around the world, then Zippopotam.us is the perfect resource for you. In this post, we'll explore what this public API has to offer, and provide some example code using JavaScript.

Getting Started

To begin using the Zippopotam.us API, you'll need to know the postal code for the location you're interested in. Once you have this information, you can make a GET request to the appropriate endpoint, and the API will return a JSON object with the relevant information.

Endpoint

The endpoint for Zippopotam.us API is as follows:

http://api.zippopotam.us/<country>/<postalcode>

Here, <country> is the two-letter country code (e.g., us for United States, ca for Canada), and <postalcode> is the actual postal code.

Example

To retrieve information for the postal code 90210 in the United States, you would use the following endpoint:

http://api.zippopotam.us/us/90210

The API will return a JSON object with the following information:

{
  "post code": "90210",
  "country": "United States",
  "country abbreviation": "US",
  "places": [
    {
      "place name": "Beverly Hills",
      "longitude": "-118.4065",
      "state": "California",
      "state abbreviation": "CA",
      "latitude": "34.0901"
    }
  ]
}

Example Code in JavaScript

Here's some example code using JavaScript to retrieve postal code information from the Zippopotam.us API:

const country = 'us';
const postalcode = '90210';
const endpoint = `http://api.zippopotam.us/${country}/${postalcode}`;

fetch(endpoint)
  .then(response => response.json())
  .then(data => console.log(data));

This code sets the country and postalcode variables, constructs the appropriate API endpoint, and uses the fetch API to make a GET request to that endpoint. Once the response is received, the code converts it to a JSON object and logs it to the console.

Conclusion

Zippopotam.us is a simple and easy-to-use API for retrieving postal code information from around the world. With just a few lines of code, you can integrate this resource into your project and start retrieving postal code information for any location you need.

Related APIs in Geocoding