Utils

Making requests with Http #

The Canvas SDK offers a helper class for completing HTTP calls.

from canvas_sdk.utils import Http
http = Http()

get #

Sends a GET request.

Parameters:

NameTypeRequiredDescription
urlstringtrueThe url of the request.
headersdictfalseThe headers to include in the request.

Example:

http = Http()
http.get("https://my-url.com/", headers={"Authorization": f"Bearer token"})

post #

Sends a POST request.

Parameters:

NameTypeRequiredDescription
urlstringtrueThe url of the request.
headersdictfalseThe headers to include in the request.
jsondictfalseThe json to include in the request.
datadict or stringfalseThe data to include in the request.

Example:

http = Http()
http.post(
    "https://my-url.com/",
    headers={"Authorization": f"Bearer token"},
    json={"post": "json"},
    data="this-is-my-data"
)

put #

Sends a PUT request.

Parameters:

NameTypeRequiredDescription
urlstringtrueThe url of the request.
headersdictfalseThe headers to include in the request.
jsondictfalseThe json to include in the request.
datadict or stringfalseThe data to include in the request.

Example:

http = Http()
http.put(
    "https://my-url.com/",
    headers={"Authorization": f"Bearer token"},
    json={"put": "json"},
    data="this-is-my-data"
)

patch #

Sends a PATCH request.

Parameters:

NameTypeRequiredDescription
urlstringtrueThe url of the request.
headersdictfalseThe headers to include in the request.
jsondictfalseThe json to include in the request.
datadict or stringfalseThe data to include in the request.

Example:

http = Http()
http.patch(
    "https://my-url.com/",
    headers={"Authorization": f"Bearer token"},
    json={"patch": "json"},
    data="this-is-my-data"
)