{"id":17968576,"url":"https://github.com/juststeveking/laravel-transporter","last_synced_at":"2025-05-15T15:05:41.948Z","repository":{"id":37595738,"uuid":"371007019","full_name":"JustSteveKing/laravel-transporter","owner":"JustSteveKing","description":"Transporter is a futuristic way to send API requests in PHP. This is an OOP approach to handling API requests.","archived":false,"fork":false,"pushed_at":"2024-10-04T07:43:57.000Z","size":309,"stargazers_count":472,"open_issues_count":3,"forks_count":26,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-04T11:47:19.041Z","etag":null,"topics":["api-client","hacktoberfest","laravel","oop"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JustSteveKing.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["JustSteveKing","zuzana-kunckova"]}},"created_at":"2021-05-26T11:18:51.000Z","updated_at":"2025-03-15T13:39:02.000Z","dependencies_parsed_at":"2024-10-29T15:03:37.481Z","dependency_job_id":null,"html_url":"https://github.com/JustSteveKing/laravel-transporter","commit_stats":{"total_commits":71,"total_committers":12,"mean_commits":5.916666666666667,"dds":0.4084507042253521,"last_synced_commit":"75aca301340beab17ba9e5c75d2d97375a29d24e"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustSteveKing%2Flaravel-transporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustSteveKing%2Flaravel-transporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustSteveKing%2Flaravel-transporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JustSteveKing%2Flaravel-transporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JustSteveKing","download_url":"https://codeload.github.com/JustSteveKing/laravel-transporter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248478219,"owners_count":21110663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","hacktoberfest","laravel","oop"],"created_at":"2024-10-29T14:40:49.033Z","updated_at":"2025-04-11T20:38:55.755Z","avatar_url":"https://github.com/JustSteveKing.png","language":"PHP","funding_links":["https://github.com/sponsors/JustSteveKing","https://github.com/sponsors/zuzana-kunckova"],"categories":[],"sub_categories":[],"readme":"# Transporter\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/juststeveking/laravel-transporter.svg?style=flat-square)](https://packagist.org/packages/juststeveking/laravel-transporter)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/JustSteveKing/laravel-transporter/run-tests.yml?branch=main\u0026label=Tests\u0026style=flat-square)](https://github.com/JustSteveKing/laravel-transporter/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/juststeveking/laravel-transporter.svg?style=flat-square)](https://packagist.org/packages/juststeveking/laravel-transporter)\n\nTransporter is a futuristic way to send API requests in PHP. This is an OOP approach to handle API requests.\n\n\u003cp align=\"center\"\u003e\n\n![](banner.png)\n\n\u003c/p\u003e\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require juststeveking/laravel-transporter\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --provider=\"JustSteveKing\\Transporter\\TransporterServiceProvider\" --tag=\"transporter-config\"\n```\n\nThe contents of the published config file:\n\n```php\nreturn [\n    'base_uri' =\u003e env('TRANSPORTER_BASE_URI'),\n];\n```\n\n## Generating Request\n\nTo generate an API request to use with Transporter, you can use the Artisan make command:\n\n```bash\nphp artisan make:api-request NameOfYourRequest\n```\n\nThis will by default publish as: `app/Transporter/Requests/NameOfYourRequest.php`\n\n\n## Usage\n\nTransporter Requests are an extention of Laravels `PendingRequest` so all of the methods available on a Pending Request is available to you on your requests.\n\nAlso when you send the request, you will receive a `Illuminate\\Http\\Client\\Response` back, allowing you to do things such as `collect($key)` and `json()` and `failed()` very easily. We are simply just shifting how we send it into a class based approach.\n\n```php\nTestRequest::build()\n    -\u003ewithToken('foobar')\n    -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ])\n    -\u003esend()\n    -\u003ejson();\n```\n\nWhen building your request to send, you can override the following:\n\n- Request Data using `withData(array $data)`\n- Request Query Params using `withQuery(array $query)`\n- Request Path using `setPath(string $path)`\n\n\n### Checking the payload\n\nI had a request in an issue to be able to see the request data for a request, so I have added a helper method called `payload` which will return whatever has been stored in the request `data` property.\n\n```php\n$request = TestRequest::build()\n    -\u003ewithToken('foobar')\n    -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ]);\n\n$data = $request-\u003epayload(); // ['title' =\u003e 'Build a package']\n```\n\n\n### Concurrent Requests\n\n```php\n$responses = \\JustSteveKing\\Transporter\\Facades\\Concurrently::build()-\u003esetRequests([\n    TestRequest::build()\n        -\u003ewithToken('foobar')\n        -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ]),\n    TestRequest::build()\n        -\u003ewithToken('foobar')\n        -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ]),\n    TestRequest::build()\n        -\u003ewithToken('foobar')\n        -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ]),\n]);\n\n$responses[0]-\u003ejson();\n$responses[1]-\u003ejson();\n$responses[2]-\u003ejson();\n```\n\n### Concurrency with a Custom key\n\n```php\n$responses = \\JustSteveKing\\Transporter\\Facades\\Concurrently::build()-\u003esetRequests([\n    TestRequest::build()\n        -\u003eas(\n            key: 'first'\n        )\n        -\u003ewithToken('foobar')\n        -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ]),\n    TestRequest::build()\n        -\u003eas(\n            key: 'second'\n        )\n        -\u003ewithToken('foobar')\n        -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ]),\n    TestRequest::build()\n        -\u003eas(\n            key: 'third'\n        )\n        -\u003ewithToken('foobar')\n        -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ]),\n]);\n\n$responses['first']-\u003ejson();\n$responses['second']-\u003ejson();\n$responses['third']-\u003ejson();\n```\n\n### Optional Alias\n\nInstead of the standard `send()` method, it is also possible to use the fun alias `energize()`. *Please note, no sound effects are included.*\n\n```php\nTestRequest::build()\n    -\u003ewithToken('foobar')\n    -\u003ewithData([\n        'title' =\u003e 'Build a package'\n    ])\n    -\u003eenergize()\n    -\u003ejson();\n```\n\n### Faking a Request or Concurrent\n\nTo fake a request, all you need to do is replace the build method with the fake method, which takes an optional `status` parameter, to set the status code being returned with the response:\n\n```php\nTestRequest::fake(\n    status: 200,\n)-\u003ewithToken('foobar')\n-\u003ewithData([\n    'title' =\u003e 'Build a package'\n])-\u003ewithFakeData([\n    'data' =\u003e 'faked'\n])-\u003esend();\n```\n\n```php\n$responses = Concurrently::fake()-\u003esetRequests([\n    TestRequest::fake()-\u003esetPath(\n        path: '/todos/1',\n    )-\u003eas(\n        key: 'first'\n    ),\n    TestRequest::fake()-\u003esetPath(\n        path: '/todos/2',\n    )-\u003eas(\n        key: 'second'\n    ),\n    TestRequest::fake()-\u003esetPath(\n        path: '/todos/3',\n    )-\u003eas(\n        key: 'thirds'\n    ),\n])-\u003erun();\n```\n\nWhich will return a response with the data you pass through to `withFakeData`, which internally will merge what is on the class with what you pass it. So you can build up an initial state of faked data per class.\n\n### Sending XML\n\nThanks to a fantastic suggestion by [@jessarcher](https://github.com/jessarcher) we can use a `Trait` to allow for easy use of XML in your requests. Using this as a trait makes a lot of sense as most APIs these days use JSON, so it is purely opt in. \nTo use this, simply use the trait on your request:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App\\Transporter\\Requests;\n\nuse JustSteveKing\\Transporter\\Concerns\\SendsXml;\nuse JustSteveKing\\Transporter\\Request;\n\nclass XmlRequest extends Request\n{\n    use SendsXml;\n    \n    protected string $method = 'POST';\n    \n    protected string $path = '/your-endpoint';\n}\n```\nThen all you need to do is call the methods:\n\n```php\nXmlRequest::build()-\u003ewithXml(\n    xml: '\u003ctodo\u003e\u003cname\u003eSend an XML Requets\u003c/name\u003e\u003ccompleted\u003efalse\u003c/completed\u003e\u003c/todo\u003e'\n)-\u003esend();\n```\n\n## Testing\n\nTo run the tests in parallel:\n\n```bash\ncomposer run test\n```\n\nTo run the tests with a coverage report:\n\n```bash\ncomposer run test-coverage\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Zuzana Kunckova](https://github.com/zuzana-kunckova)\n- [Steve McDougall](https://github.com/JustSteveKing)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuststeveking%2Flaravel-transporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuststeveking%2Flaravel-transporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuststeveking%2Flaravel-transporter/lists"}