-
Can I access the connector class from a request? So: my connector contains a property shared by multiple requests. I would like to achieve something like this in my request:
Another request might look like:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @wivaku Yes you can achieve this, however you would implement it slightly differently. It's a little hacky, but you can use the use Saloon\Helpers\URLHelper;
class UserRequest extends Request
{
/**
* The HTTP method of the request
*/
protected Method $method = Method::GET;
/**
* The endpoint for the request
*/
public function resolveEndpoint(): string
{
return '/:account/myendpoint';
}
public function boot(PendingRequest $pendingRequest): void
{
$connector = $pendingRequest->getConnector();
$baseUrl = $connector->resolveBaseUrl();
$endpoint = str_replace($this->resolveEndpoint(), ':account', $connector->getAccount());
$pendingRequest->setUrl(URLHelper::join($baseUrl, $endpoint));
}
} Above you can see I am replacing a placeholder Apologies there isn't an easier way to do this right now, I will be looking at adding a proper |
Beta Was this translation helpful? Give feedback.
Hey @wivaku
Yes you can achieve this, however you would implement it slightly differently. It's a little hacky, but you can use the
boot
method to customise the request while it is being sent