To set up the package please run following command in your project.
composer require mabjavaid/user-lib
- Laravel 8.x
- Laravel 9.x
- To get a single user by id you can call following method.
- Namespace =>
Mabjavaid\UserLib\UserLib
UserLib::getUserById($id)
- Namespace =>
- To get all users you can call following method.
- Namespace =>
Mabjavaid\UserLib\UserLib
UserLib::getAllUsers($pageNumber)
- Namespace =>
- To create a new user you can call following method.
- Namespace =>
Mabjavaid\UserLib\UserLib
UserLib::createUser($name, $job)
- Namespace =>
- C1: Remote APIs are often unstable and unreliable; how will you handle this?
- I am using custom exception
ReqresException
to communicate errors to other developers utilising this package with clear message and error code. - I develop a custom exception to handle api related exceptions
- I am catching api related exceptions and throwing custom exception with clear message and error code.
- FYI: for other validations e:g parameters i will do the following
- I will use laravel validation (Request Class => set payload using request() helper) to validate the parameters and throw custom validation exception with clear message and error code.
- I am using custom exception
- C2: How can you make your code testable?
- Unit tests are written and covering every expect of written code.
- We should never make live request to a third party when testing.A good developer will always mock the test data and response
- Package is developed using php 8.0 and laravel 9.x. It is tested on laravel 9.x and php 8.0.