Canvas
in package
Canvas facade class for making raw API calls to arbitrary Canvas URLs.
This class provides a clean, intuitive interface for making direct API calls to Canvas URLs. It's particularly useful for:
- Following pagination URLs returned by Canvas
- Calling custom or undocumented endpoints
- Processing webhook callbacks with embedded URLs
- Following URLs in API responses (e.g., file downloads)
- Accessing beta or experimental Canvas features
Tags
Table of Contents
Properties
- $httpClient : HttpClientInterface|null
Methods
- delete() : mixed
- Make a DELETE request to a Canvas URL
- get() : mixed
- Make a GET request to a Canvas URL
- patch() : mixed
- Make a PATCH request to a Canvas URL
- post() : mixed
- Make a POST request to a Canvas URL
- put() : mixed
- Make a PUT request to a Canvas URL
- request() : mixed
- Make a request to a Canvas URL with any HTTP method
- setHttpClient() : void
- Set a custom HTTP client instance
- getHttpClient() : HttpClientInterface
- Get the HTTP client instance, creating one if necessary
- isMultipartData() : bool
- Check if data should be sent as multipart
- parseResponse() : mixed
- Parse the response based on content type
- prepareMultipartData() : array<string|int, mixed>
- Prepare data for multipart encoding
Properties
$httpClient
protected
static HttpClientInterface|null
$httpClient
= null
The HTTP client instance
Methods
delete()
Make a DELETE request to a Canvas URL
public
static delete(string $url[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $url : string
-
Full URL or relative path
- $options : array<string|int, mixed> = []
-
Optional Guzzle request options
Tags
Return values
mixed —Decoded JSON response or raw response based on content type
get()
Make a GET request to a Canvas URL
public
static get(string $url[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $url : string
-
Full URL or relative path
- $options : array<string|int, mixed> = []
-
Optional Guzzle request options
Tags
Return values
mixed —Decoded JSON response or raw response based on content type
patch()
Make a PATCH request to a Canvas URL
public
static patch(string $url[, array<string|int, mixed>|null $data = null ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $url : string
-
Full URL or relative path
- $data : array<string|int, mixed>|null = null
-
Data to send in request body
- $options : array<string|int, mixed> = []
-
Optional Guzzle request options
Tags
Return values
mixed —Decoded JSON response or raw response based on content type
post()
Make a POST request to a Canvas URL
public
static post(string $url[, array<string|int, mixed>|null $data = null ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $url : string
-
Full URL or relative path
- $data : array<string|int, mixed>|null = null
-
Data to send in request body
- $options : array<string|int, mixed> = []
-
Optional Guzzle request options
Tags
Return values
mixed —Decoded JSON response or raw response based on content type
put()
Make a PUT request to a Canvas URL
public
static put(string $url[, array<string|int, mixed>|null $data = null ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $url : string
-
Full URL or relative path
- $data : array<string|int, mixed>|null = null
-
Data to send in request body
- $options : array<string|int, mixed> = []
-
Optional Guzzle request options
Tags
Return values
mixed —Decoded JSON response or raw response based on content type
request()
Make a request to a Canvas URL with any HTTP method
public
static request(string $url[, string $method = 'GET' ][, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $url : string
-
Full URL or relative path
- $method : string = 'GET'
-
HTTP method (GET, POST, PUT, DELETE, PATCH, etc.)
- $options : array<string|int, mixed> = []
-
Optional Guzzle request options
Tags
Return values
mixed —Decoded JSON response or raw response based on content type
setHttpClient()
Set a custom HTTP client instance
public
static setHttpClient(HttpClientInterface|null $client) : void
Parameters
- $client : HttpClientInterface|null
-
Pass null to reset to default
getHttpClient()
Get the HTTP client instance, creating one if necessary
protected
static getHttpClient() : HttpClientInterface
Return values
HttpClientInterfaceisMultipartData()
Check if data should be sent as multipart
protected
static isMultipartData(array<string|int, mixed> $data) : bool
Canvas API uses multipart for certain types of data, particularly when arrays are nested or when file uploads are involved.
Parameters
- $data : array<string|int, mixed>
Return values
boolparseResponse()
Parse the response based on content type
protected
static parseResponse(ResponseInterface $response) : mixed
Parameters
- $response : ResponseInterface
prepareMultipartData()
Prepare data for multipart encoding
protected
static prepareMultipartData(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
- $data : array<string|int, mixed>