About this demo
This sandbox exercises the kayrah87/dummyjson-user-connector package —
a framework-agnostic PHP 8.4 connector for the
DummyJSON users API.
Each demo page exercises one public method of
UserService, lets you submit real input, and shows the
response (or the exception that was thrown). Source-code snippets on
each page show exactly what the consumer code looks like.
Public API covered
- Get User →
getUser(int $id): User -
Fetches a single user by ID. Demonstrates happy-path JSON decoding
into the
UserDTO plus theUserNotFoundExceptionpath when the ID doesn't exist. - List Users →
listUsers(int $limit = 30, int $skip = 0): UserPage -
Paginated list. Returns a
UserPageenvelope that implementsCountableandIteratorAggregate, socount($page)andforeachjust work. - Create User →
createUser(string $firstName, string $lastName, string $email): User -
POSTs a new user. Input is trimmed and validated before
the HTTP call — bad input throws
ValidationExceptionwithout wasting a round-trip. Returns the fullUserDTO including the generatedid.
Exception hierarchy
Every error raised by the package implements the marker interface
DummyJsonException, so one catch can trap
anything from the package:
try {
$user = $service->getUser(1);
} catch (DummyJsonException $e) {
// $e is one of: UserNotFound, Validation, Transport, Api, InvalidResponse
}
UserNotFoundException— 404 responses, exposesgetUserId()ValidationException— bad input or 400 responses, exposesgetField()TransportException— network/DNS/timeout failure, exposesgetRequestMethod()/getRequestUri()ApiException— other non-2xx responses, exposesgetStatusCode()+getResponse()InvalidResponseException— malformed or unexpected response shape, exposesgetResponse()
How this demo was wired
The service is instantiated with one line:
$service = UserService::create();
That static factory uses php-http/discovery to find the
PSR-18 client and PSR-17 factories already installed in the project —
in this sandbox, that's Guzzle 7 via composer require. No
other setup needed.