antibodies-online/dhl-rest-sdk

v1.0.0 2024-11-29 11:33 UTC

This package is auto-updated.

Last update: 2024-11-29 11:36:59 UTC


README

GitHub license Packagist GitHub issues

This package provides PHP classes to interact with the DHL REST API.

Each Class is generated by Jane OpenAPI Generator. The OpenAPI Specification is provided byDHL which can be found in the root folder.

Installation

composer require antibodies-online/dhl-rest-sdk

Usage

You can use following client to interact with the DHL API.

use Antibodies\DHL\API\Rest\Client;
use Http\Discovery\Psr18ClientDiscovery;        
use Psr\Http\Client\ClientInterface;

$config = new Config();
$dhlExpressUri = 'https://express.api.dhl.com/mydhlapi/test'; 
$psrClient = Psr18ClientDiscovery::find();

 $httpClient = new PluginClient($psrClient, [
                new BaseUriPlugin($dhlExpressUri),
                new AuthenticationPlugin(
                    new BasicAuth($config->getClientId(), $config->getClientSecret())
                ),
            ]);
        }

$client = new Client::create($httpClient);      

$request = new SupermodelIoLogisticsExpressRateRequest();
// ... Fill the request object with data

 $response = $client->expApiRatesMany(
                requestBody: $request,
                queryParameters: $queryParams
            );

The selected client in this example is from Psr package and is used to send the request to the DHL API. The chosen endpoint is "rates/many" It's also needed to put in the right credentials in the AuthenticationPlugin.

Therefore you need an account at DHL and you need to create an API key. Visit https://developer.dhl.com/

Generate Classes

With following command you can generate the classes from the OpenAPI Specification.

composer generate-files

Have a look in composer.json for the script and the configuration from file .jane. It tells jane where the origin file location is and where to put the generated files. Additionally you can set a namespace for the generated files.

Export OpenAPI Specification

By adding the package "jane-php/open-api-runtime" you are able to export the OpenAPI Specification from the generated classes. We assume you use a Symfony project. Therefore you can use the following command to export the OpenAPI Specification.

bin/console api:openapi:export --output=dhl-api-rest.json

Documentations

https://developer.dhl.com/api-reference/dhl-express-mydhl-api#get-started-section/

Contributing

Really appreciate bug reports. Feel free to ask for additional functionality/fields. But be aware not all feature may be implemented. A Pull Request for your Features would be amazing.

License

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