An open API service indexing awesome lists of open source software.

https://github.com/kubinyete/template-sdk-php

Basic quick-start template for creating Webservice clients
https://github.com/kubinyete/template-sdk-php

Last synced: 7 months ago
JSON representation

Basic quick-start template for creating Webservice clients

Awesome Lists containing this project

README

          

# Template SDK/Webservice Project

## What?
This project provides a basic quick-start template for creating Webservice clients.

## Why?
Instead of repeating the same things over and over again for every webservice client that your application needs, this template provides a quick and easy solution for
building and mapping endspoints to your client, providing a structured approach for endpoint representation, environment mapping and error handling.

## How?
To get started, just extend the base `Core/Client` and create your first endpoint, following the example below:

```php
# OpenMeteoClient.php
getParsedPath('error')) {
throw new OpenMeteoException((string)$response->getParsedPath('reason'), 0, null, $response);
}

return $response;
}

// @NOTE:
// Translating Client/Server errors
protected function exceptionThrown(Throwable $e): void
{
if ($e instanceof HttpException && $e->getResponse()) {
$this->responseReceived($e->getResponse());
}

throw $e;
}
}
```
```php
# ForecastEndpoint.php
get($forecastSettings->jsonSerialize());
return Forecast::parse($response->getParsed());
}
}
```
```php
# usage.php
forecast()->now(new ForecastSettings(52.52, 13.41, true));
var_dump($forecast);
} catch (HttpClientException $e) {
echo "Bad request!" . PHP_EOL;
echo "Message: {$e->getMessage()}" . PHP_EOL;
echo "Response: {$e->getResponse()->getBody()}" . PHP_EOL;
}

```