Documentation

HttpClient
in package
implements HttpClientInterface

HTTP client for Canvas LMS API communication.

Handles all HTTP requests to the Canvas API including authentication via Bearer tokens, response pagination, error handling, and middleware support. Implements the HttpClientInterface to provide a consistent API for making requests to Canvas LMS endpoints.

Table of Contents

Interfaces

HttpClientInterface

Properties

$client  : ClientInterface
$handlerStack  : HandlerStack
$logger  : LoggerInterface
$middleware  : array<string, MiddlewareInterface>

Methods

__construct()  : mixed
addMiddleware()  : void
Add middleware to the stack
delete()  : ResponseInterface
delete request
get()  : ResponseInterface
Get request
getLogger()  : LoggerInterface
Get the logger instance
getMiddleware()  : array<string, MiddlewareInterface>
Get registered middleware
getPaginated()  : PaginatedResponse
Get request with pagination support
patch()  : ResponseInterface
Patch request
post()  : ResponseInterface
Post request
put()  : ResponseInterface
Put request
rawRequest()  : ResponseInterface
Make a raw request to any Canvas URL
removeMiddleware()  : void
Remove middleware from the stack
request()  : ResponseInterface
Make an HTTP request
requestPaginated()  : PaginatedResponse
Make an HTTP request with pagination support
getDefaultMiddleware()  : array<string|int, MiddlewareInterface>
Get default middleware stack
getValidOAuthToken()  : string|null
Get a valid OAuth token, refreshing if necessary.
prepareDefaultOptions()  : array<string|int, mixed>
prepareRawRequestOptions()  : array<string|int, mixed>
Prepare options for raw requests
validateCanvasUrl()  : void
Validate that a URL points to the configured Canvas domain

Properties

$handlerStack

private HandlerStack $handlerStack

Methods

__construct()

public __construct([ClientInterface|null $client = null ][, LoggerInterface|null $logger = null ][, array<string|int, MiddlewareInterface$middleware = [] ]) : mixed
Parameters
$client : ClientInterface|null = null
$logger : LoggerInterface|null = null
$middleware : array<string|int, MiddlewareInterface> = []

getLogger()

Get the logger instance

public getLogger() : LoggerInterface
Return values
LoggerInterface

rawRequest()

Make a raw request to any Canvas URL

public rawRequest(string $url[, string $method = 'GET' ][, array<string|int, mixed> $options = [] ]) : ResponseInterface

This method allows direct API calls to arbitrary Canvas URLs, useful for:

  • Following pagination URLs returned by Canvas
  • Calling custom or undocumented endpoints
  • Handling webhook callbacks with URLs
  • Following URLs provided in Canvas API responses
  • Accessing beta/experimental endpoints
Parameters
$url : string

Full URL or relative path

$method : string = 'GET'

HTTP method (GET, POST, PUT, DELETE, PATCH, etc.)

$options : array<string|int, mixed> = []

Guzzle request options

Tags
throws
CanvasApiException
throws
MissingApiKeyException
throws
MissingBaseUrlException
throws
MissingOAuthTokenException
Return values
ResponseInterface

removeMiddleware()

Remove middleware from the stack

public removeMiddleware(string $name) : void
Parameters
$name : string

getValidOAuthToken()

Get a valid OAuth token, refreshing if necessary.

private getValidOAuthToken() : string|null
Return values
string|null

The valid OAuth token or null if not available

validateCanvasUrl()

Validate that a URL points to the configured Canvas domain

private validateCanvasUrl(string $url) : void
Parameters
$url : string

The URL to validate

Tags
throws
CanvasApiException

        
On this page

Search results