Skip to content

About

A simple demp PHP API client using Guzzle that follows best practices

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

API Consumer

A simple PHP API client using Guzzle that follows best practices

Best practices

  • PSR-4 autoloading (App\Api\ApiClient in src/Api/).
  • Dependency injection (base URI + config passed in constructor).
  • Error handling with RequestException and JSON validation.
  • Separation of concerns (request handling vs. response decoding).
  • Reusable client wrapper (GET and POST, easily extendable).
  • Interface-driven design
  • Add an alternative datasource querying a MySQL database or SqlLite db
  • Configuration via environment
  • Request logging (Guzzle Middleware)
  • Docker environment
  • PHPUnit testing setup

Docker

docker build -t sonet/apache-bullseye:8.3 .
docker run --rm -d -p 8080:80 -v $PWD:/var/www/html --name restapi -e DOCUMENT_ROOT='/var/www/html'  sonet/apache-bullseye:8.3
sh


## Run tests
NOTE: PHPUnit requires the "dom", "json", "libxml", "mbstring", "tokenizer", "xml", "xmlwriter" extensions, but the "dom", "xml", "xmlwriter" extensions.

```sh
./vendor/bin/phpunit

About

A simple demp PHP API client using Guzzle that follows best practices

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages