Engee documentation

HTTP Support Package

Page in progress.

Subsystem Engee.Integrations provides the user with the ability to act as an HTTP client to communicate with external services via the REST API.

function close_session(device::HttpType)::Nothing

De-initialization of a previously created HTTP client.

Arguments

device::HttpType: an object of the HTTP.Http() type.

function delete(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

DELETE is a REST API request. Returns HTTPResponse — an object with the server response containing:

  • text_content: HTTP response in text representation;

  • bytes_content: HTTP response in byte representation;

  • elapsed: request completion time;

  • status_code: status code of the HTTP request.

Server response example

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

Arguments

  • device::HttpType: an object of the HTTP.Http() type.

  • endpoint::String: the endpoint for accessing an HTTP resource.

  • request_data::HTTPRequestData: request data (an HTTPRequestData object).

  • headers::Dict{String, String}: additional headings. For example, setting up connection headers and MIME-type requests:

julia-repl headers = Dict{String, String}() headers["connection"] = "keep-alive" headers["Accept"] = "application/json"

  • timeout::Union{Int64, Nothing}: таймаут на ожидание ответа в секундах.

function get(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

GET-запрос REST API. Возвращает HTTPResponse — объект с ответом сервера, содержащий:

  • text_content: HTTP-ответ в текстовом представлении;

  • bytes_content: HTTP-ответ в байтовом представлении;

  • elapsed: время выполнения запроса;

  • status_code: статус код HTTP-запроса.

Пример ответа сервера

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

Аргументы

  • device::HttpType: объект типа HTTP.Http().

  • endpoint::String: конечная точка для обращения к HTTP-ресурсу.

  • request_data::HTTPRequestData: объект типа HTTPRequestData.

  • headers::Dict{String, String}: дополнительные заголовки. Например, настройка заголовков соединения и MIME-type запросов:

julia-repl headers = Dict{String, String}() headers["connection"] = "keep-alive" headers["Accept"] = "application/json"

  • timeout::Union{Int64, Nothing}: таймаут на ожидание ответа в секундах.

function init_session(device::HttpType, base_url::String="", auth::Union{Tuple{String}, String, Nothing}=nothing, auth_type::String="bearer", headers::Dict{String, String}=Dict(), timeout::Int64=30, verify_ssl::Bool=true)::Bool

Инициализация HTTP клиента для общения с HTTP-сервером.

Аргументы

  • device::HttpType: объект типа HTTP.Http().

  • base_url::String: базовый URL для всех запросов.

  • auth::Union{Tuple{String}: данные для авторизации, либо кортеж (username, password), либо строка с токеном.

  • auth_type::String: тип аутентификации (basic, digest, или bearer).

  • headers::Dict{String, String}: заголовки по умолчанию для включения в каждый запрос.

  • timeout::Int64: таймаут ожидания ответа по умолчанию в секундах.

  • verify_ssl::Bool: верификация SSL сертификатов (true — включена, false — отключена).

function patch(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

PATCH-запрос REST API. Возвращает HTTPResponse — объект с ответом сервера, содержащий:

  • text_content: HTTP-ответ в текстовом представлении;

  • bytes_content: HTTP-ответ в байтовом представлении;

  • elapsed: время выполнения запроса;

  • status_code: статус код HTTP-запроса.

Пример ответа сервера

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

Arguments

  • device::HttpType: an object of the HTTP.Http() type.

  • endpoint::String: the endpoint for accessing an HTTP resource.

  • request_data::HTTPRequestData: an HTTPRequestData object.

  • headers::Dict{String, String}: additional headings. For example, setting up connection headers and MIME-type requests:

= "keep-alive" headers["Accept"] = "application/json"]`

  • timeout::Union{Int64, Nothing}: timeout for waiting for a response in seconds.

function post(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

POST-запрос REST API. Возвращает HTTPResponse — объект с ответом сервера, содержащий:

  • text_content: HTTP-ответ в текстовом представлении;

  • bytes_content: HTTP-ответ в байтовом представлении;

  • elapsed: время выполнения запроса;

  • status_code: статус код HTTP-запроса.

Пример ответа сервера

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

Аргументы

  • device::HttpType: объект типа HTTP.Http().

  • endpoint::String: конечная точка для обращения к HTTP-ресурсу.

  • request_data::HTTPRequestData: объект типа HTTPRequestData.

  • headers::Dict{String, String}: дополнительные заголовки. Например, настройка заголовков соединения и MIME-type запросов:

julia-repl headers = Dict{String, String}() headers["connection"] = "keep-alive" headers["Accept"] = "application/json"

  • timeout::Union{Int64, Nothing}: таймаут на ожидание ответа в секундах.

function put(device::HttpType, endpoint::String, request_data::HTTPRequestData, headers::Dict{String, String}=Dict(), timeout::Union{Int64, Nothing}=nothing)::HTTPResponse

PUT-запрос REST API. Возвращает HTTPResponse — объект с ответом сервера, содержащий:

  • text_content: HTTP-ответ в текстовом представлении;

  • bytes_content: HTTP-ответ в байтовом представлении;

  • elapsed: время выполнения запроса;

  • status_code: статус код HTTP-запроса.

Пример ответа сервера

Base.@kwdef struct HTTPResponse
text_content::Union{String, Nothing} = nothing
bytes_content::Union{Vector{UInt8}, Nothing} = nothing
elapsed::Union{HTTPTimedelta, Nothing} = nothing
status_code::Union{Int64, Nothing} = nothing
end

Аргументы

  • device::HttpType: объект типа HTTP.Http().

  • endpoint::String: конечная точка для обращения к HTTP-ресурсу.

  • request_data::HTTPRequestData: объект типа HTTPRequestData.

  • headers::Dict{String, String}: дополнительные заголовки. Например, настройка заголовков соединения и MIME-type запросов:

julia-repl headers = Dict{String, String}() headers["connection"] = "keep-alive" headers["Accept"] = "application/json"

  • timeout::Union{Int64, Nothing}: таймаут на ожидание ответа в секундах.

function remove_header(device::HttpType, key::String)::Nothing

Функция для удаления указанного заголовков запроса из существующих заголовков.

Аргументы

  • device::HttpType: объект типа HTTP.Http().

  • key::String: ключ устанавливаемого заголовка запроса.

Удаляет заголовок из всех последующих запросов.

function set_header(device::HttpType, key::String, value::String)::Nothing

A function for setting request headers to already existing headers.

Arguments

  • device::HttpType: an object of the HTTP.Http() type.

  • key::String: the key of the request header to be set.

Выставляет заголовок для всех последующих запросов.