Skip to content

Latest commit

 

History

History

php

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Zip Codes Lookup API - PHP Package

Zip Codes Lookup finds all postal codes within a US city or resolves a five-digit ZIP code to its city and state. Paid plans add the IANA time zone, geographic coordinates and the distance from the ZIP to a second ZIP.

Installation

Install via Composer:

composer require apiverve/zipcodes

Getting Started

Get your API key at APIVerve

Basic Usage

<?php

require_once 'vendor/autoload.php';

use APIVerve\Zipcodes\Client;

// Initialize the client
$client = new Client('YOUR_API_KEY');

// Make a request
$response = $client->execute([
    'zip' => '64082',
    'distanceTo' => '64106'
]);

// Print the response
print_r($response);

Error Handling

use APIVerve\Zipcodes\Client;
use APIVerve\Zipcodes\Exceptions\APIException;
use APIVerve\Zipcodes\Exceptions\ValidationException;

try {
    $response = $client->execute(['zip' => '64082', 'distanceTo' => '64106']);
    print_r($response['data']);
} catch (ValidationException $e) {
    echo "Validation error: " . implode(', ', $e->getErrors());
} catch (APIException $e) {
    echo "API error: " . $e->getMessage();
    echo "Status code: " . $e->getStatusCode();
}

Debug Mode

// Enable debug logging
$client = new Client(
    apiKey: 'YOUR_API_KEY',
    debug: true
);

Example Response

{
  "status": "ok",
  "error": null,
  "data": {
    "zipcode": "64082",
    "state_abbr": "MO",
    "latitude": "38.850243",
    "longitude": "-94.39570",
    "city": "Lees Summit",
    "state": "Missouri",
    "timezone": "America/Chicago",
    "distance": {
      "zipcode": "64106",
      "city": "Kansas City",
      "state_abbr": "MO",
      "miles": 19.94,
      "kilometers": 32.09
    }
  }
}

Requirements

  • PHP 7.4 or higher
  • Guzzle HTTP client

Documentation

For more information, visit the API Documentation.

Support

License

This package is available under the MIT License.