Looking to hire Laravel developers? Try LaraJobs

laravel-usps-addresses maintained by chrishardie

Description
Laravel package that provides a simple facade to the USPS Addresses API
Author
Last update
2026/01/08 22:53 (dev-main)
License
Downloads
759

Comments
comments powered by Disqus

Laravel USPS Addresses

Latest Version on Packagist Total Downloads

Laravel package that provides a simple facade to the USPS Addresses API

Installation

You can install the package via composer:

composer require chrishardie/laravel-usps-addresses

Define required variables in .env, available from your app's configuration in the USPS Developers Dashboard:

USPS_CLIENT_ID=
USPS_CLIENT_SECRET=

You can optionally publish the config file with:

php artisan vendor:publish --tag="laravel-usps-addresses-config"

This is the contents of the published config file:

return [
    'base_url' => env('USPS_ADDRESSES_BASE_URL', 'https://apis.usps.com/addresses/v3'),

    'oauth' => [
        'token_url' => env('USPS_OAUTH_TOKEN_URL', 'https://apis.usps.com/oauth2/v3/token'),
        'client_id' => env('USPS_CLIENT_ID'),
        'client_secret' => env('USPS_CLIENT_SECRET'),
        'scope' => 'addresses',
    ],

    'timeout' => 10,
];

Usage

use UspsAddress;

$result = UspsAddress::verify([
    'streetAddress' => '2704 Erie Ave',
    'city' => 'Cincinnati',
    'state' => 'OH',
]);

if ($result->isValid()) {
    echo $result->address->streetAddress;
};

Methods available correspond to available API endpoints:

  • UspsAddress::verify(): Returns the best standardized address for a given address.
  • UspsAddress::cityState(): Returns the city and state for a given ZIP Code.
  • UspsAddress::zipCode(): Returns the ZIP Code for a given address.

View the USPS API documentation for details about available parameters and responses.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.