Sending Requests
Last updated
Last updated
To start sending requests, instantiate your connector class and request class and use the send
or sendAsync
methods. When using the send
method. you will receive a Response
class.
Saloon supports asynchronous requests out of the box. Use the sendAsync
method, and you will receive an instance of PromiseInterface
. Saloon uses Guzzle's Promises library, which uses the A+ standard. .
You have the following methods available on the solo request.
send(MockClient $mockClient = null)
sendAsync(MockClient $mockClient = null)
createPendingRequest
connector
With previous versions of Saloon, you could send a request directly without having to use a connector to send a request. While sending requests through the connector has many benefits, you may wish to add this feature with the HasConnector
trait on your request.
Once you have added the trait to your request, make sure to add the connector
protected property and define your connector class. You may instead extend the resolveConnector
method if you need a more advanced solution.
When defining a connector with a property, you must not have any constructor properties on your connector.
Now you can use the following methods on your request.
send(MockClient $mockClient = null)
sendAsync(MockClient $mockClient = null)
createPendingRequest
connector
You may also overwrite any headers, query parameters, HTTP client config and request body on the connector or request. Read through the sections above for all the methods on the request property methods.
Saloon supports all the features Guzzle offers for asynchronous requests, including unwrapping promises and request pooling for high-performance API calls.
Please make sure to read the section on first to configure your request. You can send solo requests directly.
When sending multiple requests for the same service, use the same connector instance as it has a over using a new connector instance for every request.