Previously you could define custom methods on the connector to call requests in Saloon, like so:
protected array $requests = [
'getMyUser' => UserRequest::class,
ErrorRequest::class,
];
This was pretty limited as you couldn't define "groups" of requests.
This PR introduces an extension to this API and now you can define an array of requests, keyed for a collection or a custom "RequestCollection" which is a class that extends the base "RequestCollection" class and can have completely custom methods inside. You will also have access to the connector.
Define groups of requests
$connector->user()->get()
protected array $requests = [
'user' => [
'get' => UserRequest::class,
],
];
Define custom request collections
$connector->user()->get()
protected array $requests = [
'user' => UserCollection::class,
];
class UserCollection extends RequestCollection
{
public function get(): SaloonRequest
{
return $this->connector->request(new UserRequest);
}
}
What's Changed
- Feature | Nested SDK Requests by @Sammyjo20 in #59
Full Changelog: v1.1.0...v1.2.0