Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Zipcodebase

No security coverage Under active development

This module provides a Drupal service to integrate with the Zipcodebase API, allowing you to access worldwide postal code data for validation, lookups, and distance calculations. It is intended to be used by other modules to leverage this external data.

This module integrates Drupal with https://zipcodebase.com/. Zipcodebase is a third-party service that will allow you free access to Worldwide Postal Code Data.

As per the Zipcodebase website:

Zipcodebase.com is the perfect tool to perform postal code validation, lookups and other calculative tasks, such as postal code distance calculations. Zipcodebase offers a wide range of endpoints that give you access to any type of data you might need.

Read the zipcodebase documentation for more detail.

This is a simple wrapper for the Zipcodebase API. This module exposes a Drupal service that can be used to query the API.

Dependencies

This module uses the msankhala/zipcodebase-php composer package.

Installation

composer require drupal/zipcodebase

Uses

This module doesn't provide any functionality on its own. It is meant to be used by other modules.

See available methods that can be called on zipcodebase client.

Example: Using the ZipCodeBaseService in a controller

<?php

namespace Drupal\zipcodebase\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\zipcodebase\ZipCodeBaseService;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Class TestController controller.
 */
class TestController extends ControllerBase {

  /**
   * Logger factory.
   *
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $loggerFactory;

  /**
   * The ZipCodeBaseService.
   *
   * @var \Drupal\zipcodebase\ZipCodeBaseService
   */
  protected $zipCodeBaseService;

  /**
   * TestController constructor.
   *
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory
   *   The logger factory.
   * @param \Drupal\zipcodebase\ZipCodeBaseService $zipCodeBaseService
   *   The ZipCodeBaseService.
   */
  public function __construct(LoggerChannelFactoryInterface $loggerFactory, ZipCodeBaseService $zipCodeBaseService) {
    $this->loggerFactory = $loggerFactory;
    $this->zipCodeBaseService = $zipCodeBaseService;
  }

  /**
   * {@inheritdoc}
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The Drupal service container.
   *
   * @return static
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('logger.factory'),
      $container->get('zipcodebase.zipcodebase')
    );
  }

  /**
   * Test.
   *
   * @return string
   *   Return Hello string.
   */
  public function test() {
    $this->loggerFactory->get('zipcodebase')->notice('TestController::test() called');
    $zipCodeBaseClient = $this->zipCodeBaseService->getClient();
    $credits = $zipCodeBaseClient->getCredits();
    return [
      '#type' => 'markup',
      '#markup' => "Credits: " . print_r($credits, TRUE),
    ];
  }

}
Drupal 8–10 · not 11

Ask your assistant about Zipcodebase

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
May 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core PHP Release date
1.0.0 Stable 8–10 May 19, 2023
1.0.x-dev Dev 8–10 May 18, 2023