定制 lendable/dvla-vehicle-enquiry-api-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lendable/dvla-vehicle-enquiry-api-client

最新稳定版本:v1.0.1

Composer 安装命令:

composer require lendable/dvla-vehicle-enquiry-api-client

包简介

API client for the DVLA's Vehicle Enquiry Service API

README 文档

README

Latest Stable Version License

PHP client implementation for the DVLA Vehicle Enquiry API v1. This package provides:

  • API client that supports PSR-18 HTTP clients
  • token-based authentication
  • value objects for the request building and for the response

Installation

You can install the library via Composer.

composer require lendable/dvla-vehicle-enquiry-api-client

Usage

The Client class implements the DVLA's REST API and can return the vehicles scope which can be used to request the vehicle details.

For the instantiation of the Client class we need to inject the decorators which adds the API key authentication, and the PSR-18 compatibility layers. Also, we need to define the API's base URI to easily switch between UAT and live service.

Base URI

The API's specification contains the UAT and live URL. The given URI should not end with slash (/) and should contain the /v1 path too.

For example: https://uat.driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1

The client accepts the URI in any PSR-7 UriInterface implementation.

Authentication

The ApiKeyAuthHttpClientDecorator adds the required API token authentication headers to the requests. The ApiKey value object keeps the token secret, avoiding accidental exposure.

HTTP client

With the Psr18ClientDecorator you can use any HTTP client which supports the PSR-18 standard to perform the prebuilt HTTP request.

If you prefer to use an HTTP client that doesn't support the PSR-18 standard, you can alternatively make a simple decorator that calls the HTTP client using the PSR-18 RequestInterface format request data and convert the HTTP client's response to a PSR-18 ResponseInterface format response.

For example in our integration test we are using GuzzleClient with a decorator which using this PSR-18 conversion.

Example request

<?php

declare(strict_types=1);

use Lendable\Dvla\VehicleEnquiry\Auth\ApiKeyAuthHttpClientDecorator;
use Lendable\Dvla\VehicleEnquiry\Auth\ValueObject\ApiKey;
use Lendable\Dvla\VehicleEnquiry\Client;
use Lendable\Dvla\VehicleEnquiry\Psr18ClientDecorator;
use Lendable\Dvla\VehicleEnquiry\Scope\VehiclesScope\Request\EnquiryRequest;
use Lendable\Dvla\VehicleEnquiry\Scope\VehiclesScope\ValueObject\RegistrationNumber;
use Nyholm\Psr7\Uri;

$client = new Client(
        new ApiKeyAuthHttpClientDecorator(
            new Psr18ClientDecorator(
                new YourPsr18HttpClient()
            ),
            ApiKey::fromString('YOUR-AUTHENTICATION-TOKEN')
        ),
        new Uri('https://uat.driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1')
    );

$vehicleDetails = $client->vehicles()->enquireDetails(
        EnquiryRequest::with(RegistrationNumber::fromString('AA19PPP'))
    );

This makes an API request with the AA19PPP registration number and the $vehicleDetails variable will contain an EnquiryResponse object which contains all the returned API response data in value objects.

This example is using the UAT API URL and a test registration number. Test registration numbers for mock responses of the different test cases are available in the DVLA Vehicle Enquiry Service API documentation.

统计信息

  • 总下载量: 53.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 41
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2021-08-10