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
- Host: GitHub
- URL: https://github.com/kubinyete/template-sdk-php
- Owner: Kubinyete
- Created: 2023-01-05T19:16:23.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-22T12:50:17.000Z (over 1 year ago)
- Last Synced: 2024-05-22T13:33:14.235Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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;
}```