HTTP Support Package
Subsystem Engee.Integrations provides the user with the ability to act as an HTTP client to communicate with external services via the REST API.
#
Main.EngeeDeviceManager.Devices.HTTP.Http — Type
#
Main.EngeeDeviceManager.Devices.HTTP.close_session — Method
function close_session(device::HttpType)::Nothing
De-initialization of a previously created HTTP client.
Arguments
device::HttpType: an object of the HTTP.Http() type.
#
Main.EngeeDeviceManager.Devices.HTTP.close_session — Method
#
Main.EngeeDeviceManager.Devices.HTTP.delete — Function
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}: таймаут на ожидание ответа в секундах.
#
Main.EngeeDeviceManager.Devices.HTTP.get — Function
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}: таймаут на ожидание ответа в секундах.
#
Main.EngeeDeviceManager.Devices.HTTP.init_session — Function
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— отключена).
#
Main.EngeeDeviceManager.Devices.HTTP.patch — Function
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.
#
Main.EngeeDeviceManager.Devices.HTTP.post — Function
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}: таймаут на ожидание ответа в секундах.
#
Main.EngeeDeviceManager.Devices.HTTP.put — Function
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}: таймаут на ожидание ответа в секундах.
#
Main.EngeeDeviceManager.Devices.HTTP.remove_header — Method
function remove_header(device::HttpType, key::String)::Nothing
Функция для удаления указанного заголовков запроса из существующих заголовков.
Аргументы
-
device::HttpType: объект типа HTTP.Http(). -
key::String: ключ устанавливаемого заголовка запроса.
#
Main.EngeeDeviceManager.Devices.HTTP.remove_header — Method
Удаляет заголовок из всех последующих запросов.
#
Main.EngeeDeviceManager.Devices.HTTP.set_header — Method
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.
#
Main.EngeeDeviceManager.Devices.HTTP.set_header — Method
Выставляет заголовок для всех последующих запросов.