Documentation

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
example
// Following pagination
$nextPage = Canvas::get($courses->getNextUrl());

// Custom endpoint
$analytics = Canvas::get('/api/v1/custom/analytics');

// Create resource
$result = Canvas::post('/api/v1/courses/123/custom_resources', [
    'name' => 'My Resource'
]);

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

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
throws
CanvasApiException
throws
MissingApiKeyException
throws
MissingBaseUrlException
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
throws
CanvasApiException
throws
MissingApiKeyException
throws
MissingBaseUrlException
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
throws
CanvasApiException
throws
MissingApiKeyException
throws
MissingBaseUrlException
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
throws
CanvasApiException
throws
MissingApiKeyException
throws
MissingBaseUrlException
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
throws
CanvasApiException
throws
MissingApiKeyException
throws
MissingBaseUrlException
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
throws
CanvasApiException
throws
MissingApiKeyException
throws
MissingBaseUrlException
Return values
mixed

Decoded JSON response or raw response based on content type

isMultipartData()

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
bool

parseResponse()

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>
Return values
array<string|int, mixed>

        
On this page

Search results