christiancocco / swapi
Swapi Integration for Laravel
Installs: 36
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:package
Requires
- guzzlehttp/guzzle: ^7.0
- inertiajs/inertia-laravel: dev-master
- laravel/framework: ^8.0
- phpunit/phpunit: ^9.5.10
This package is auto-updated.
Last update: 2024-06-03 19:41:08 UTC
README
Table of Contents
About Swapi
"Swapi package" is a simple wrapper package that provide the list of people and the information related to a planet accessible using the following APIs:
- GET /api/people (Provide a paginated list of people, filterable and orderable)
- GET /api/people/{peopleId} (Provide selected people data including planet details)
Technologies
Laravel 8.*
Dependencies
guzzlehttp/guzzle
phpunit/phpunit
inertiajs/inertia-laravel
Install and configure Swapi Package
To install Swapi package run this command:
composer require christiancocco/swapi --with-all-dependencies
Now you can configure testing environment file to be able to run test script.
- Create testing DB
- Create .env.testing file in your root application folder and change DB connection parameter
- Add following to phpunit.xml file:
<?xml version="1.0" encoding="UTF-8"?> <!-- ... --> <testsuites> <!-- ... --> <testsuite name="SwapiUnit"> <directory suffix="Test.php">./vendor/christiancocco/swapi/tests/Unit</directory> </testsuite> <testsuite name="SwapiTest"> <directory suffix="Test.php">./vendor/christiancocco/swapi/tests/Feature</directory> </testsuite> </testsuites>
Usage
After installation you have to run the following command:
php artisan swapi:install
This command initialize package (copy configuration file) and run migration for planet and people table.
php artisan swapi:init
This command initialize data retrieved data from swapi.dev.
(Full documentation: https://swapi.dev/documentation)
NB. To initialize testing database run this command:
php artisan migrate --env=testing
If you want to filtering, ordering and paging /api/people result you can use this querystring parameter:
- query: string to search in all people fields
- itemperpage: item per page (default value = 10)
- page: page number
- sort: sorting field
- sortVer: sorting versus (ASC: ascending - default value; DESC: descending)
Example: /api/people?query=fair&sort=name&sortVer=DESC&itemperpage=2&page=2
Testing
To launch the Unit Test run this command:
php artisan test --filter=Swapi --stop-on-failure
To test api run
php artisan serve
and visit
http://localhost:8000/swapi-test
License
The Swapi Laravel package is open-sourced software licensed under the MIT license.