๐Ÿšช
Saloon
๐Ÿง‘โ€๐Ÿ’ป View Code On Github๐Ÿค  Version 3 is out!๐Ÿ’– Support The Project
v1 (Security Fixes Only)
v1 (Security Fixes Only)
  • ๐ŸšชSaloon
  • ๐Ÿš€Getting Started
    • Installation
  • ๐Ÿค The Basics
    • Connectors
    • Requests
    • Attaching Data
    • Query Parameters
    • Sending Requests
    • Responses
      • Data Transfer Objects
    • Building SDKs
  • ๐Ÿ‘Next Steps
    • Authentication
    • Plugins
    • Caching
    • Mocking Responses
      • Non-Laravel / PHP
      • Laravel
      • Recording Requests
  • ๐ŸงชAdvanced
    • OAuth2 Authentication
    • Response Interceptors
    • Handlers / Middleware
  • โญFinish
    • Showcase
    • Tutorials
    • View Code On GitHub
    • Update Docs
    • About Me
    • Donate
Powered by GitBook
On this page
  • Sending requests using the request class
  • Sending requests using the connector class
  • Sending requests inside an SDK
  • Modifying the request before it is sent
Edit on GitHub
  1. The Basics

Sending Requests

After you have created your request, it is ready to be sent off to the internet! ๐Ÿš€

There are three ways to send requests. You can use the request class directly, send requests through your connector, or you can register requests on your connector and use method-style access to send your requests.

Sending requests using the request class

Just instantiate your request class and use the send() method.

<?php

$request = new GetForgeServerRequest(serverId: '123456');

$response = $request->send();

Sending requests using the connector class

This is useful if your connector has any constructor arguments. Just instantiate your connector class and use the send() method.

<?php

$connector = new ForgeConnector($apiToken);
$request = $connector->request(new GetForgeServerRequest(serverId: '123456'));

$response = $request->send();

// or...

$connector->send(new GetForgeServerRequest(serverId: '123456'));

Connector Constructors

Alternatively, you can overwrite the connector that a request uses, by using the setConnector() method on the request before calling the send() method.

<?php

$connector = new ForgeConnector($apiKey);
$request = new GetForgeServerRequest(serverId: '123456');

$request->setConnector($connector);

$request->send();

Sending requests inside an SDK

Modifying the request before it is sent

As mentioned previously, you can also use methods like addHeader() and setConfig() right before you send the request. This is useful if you have conditional headers, config or form data you need to pass in at the last minute.

<?php

use Sammyjo20\Saloon\Http\SaloonConnector;
use App\Http\Saloon\Requests\GetForgeServerRequest;

$request = new GetForgeServerRequest(serverId: '123456');

$request->setHeaders($array);
$request->addConfig('debug', true);
$request->addData('my-field', 'my-value');

$response = $request->send();

// Or if you are using the connector...

$connector = new ForgeConnector;
$request = $connector->request(new GetForgeServerRequest(serverId: '123456'));

$request->setHeaders($array);
$request->addConfig('debug', true);
$request->addData('my-field', 'my-value');

$response = $request->send();

// Or if you are using method-style access

$request = ForgeConnector::getForgeServerRequest(serverId: '123456');

$request->setHeaders($array);
$request->addConfig('debug', true);
$request->addData('my-field', 'my-value');

$response = $request->send();

Last updated 2 years ago

If your connector has a constructor inside with specific data, you should consider sending requests through the connector rather than the request.

Saloon offers a great framework for building SDKs.

The addData, setData and mergeData methods will not do anything unless you .

๐Ÿค 
Click here to read more
attach a form data trait
Click here to read more.