createUser(string $firstName, string $lastName, string $email): User
Creates a user via POST /users/add. Input passes through
NewUserInput, which validates client-side before
any HTTP call — empty fields, whitespace-only values, invalid
email format, or control characters all raise
ValidationException without wasting a round-trip.
Returns the full User DTO — the new id is
available as $user->id. Input is also trimmed on the
way in, so " Alice " becomes "Alice"
before being sent.
Simulated endpoint caveat: DummyJSON's
POST /users/add does not actually persist the user. The
returned id is sequential (e.g. 209) but is
not retrievable via a later getUser() call. The connector
faithfully mirrors that behaviour — do not assume round-trip.
Throws: ValidationException (client-side
rules or a 400 response from the API),
TransportException, ApiException,
InvalidResponseException.
Try it
Try submitting valid input for the happy path — or leave a field empty,
enter not-an-email, or pad a name with spaces to see
validation behaviour.
Consumer code
use Kayrah87\DummyJsonUserConnector\Exception\ValidationException;
use Kayrah87\DummyJsonUserConnector\Service\UserService;
$service = UserService::create();
try {
$user = $service->createUser(
firstName: 'Alice',
lastName: 'Smith',
email: 'alice@example.com',
);
printf("created user #%d\n", $user->id);
} catch (ValidationException $e) {
printf("invalid input on field %s: %s\n", $e->getField() ?? '(unknown)', $e->getMessage());
}