danilopucci
Intermediate OT User
Hello community,
I would like to introduce a module that I see some guys requesting it here in otland, I started to work some time ago and now it is ready: HttpClient module
You can find full code details on this pull-request.
How does it works?
It is based on http client lib. There is a dedicated thread, very similar to DatabaseTasks which will handle requests both comming from C++ or Lua context.
How to use it in lua?
The syntax is pretty much simple, and it is very similar(and inspired) to Requests lib, from Python.
For usage in C++, check the pull-request
For what is this used for?
It can be used to multiple things, the main usage is to make integration to API services, like:
Hope you enjoy
I would like to introduce a module that I see some guys requesting it here in otland, I started to work some time ago and now it is ready: HttpClient module
You can find full code details on this pull-request.
How does it works?
It is based on http client lib. There is a dedicated thread, very similar to DatabaseTasks which will handle requests both comming from C++ or Lua context.
How to use it in lua?
The syntax is pretty much simple, and it is very similar(and inspired) to Requests lib, from Python.
LUA:
-- define a callback
local function requestCallback(response)
--[[response is a table with current fields:
"requestId", "version", "statusCode", "location", "contentType", "responseTimeMs", "headerData", "bodySize", "bodyData", "success", "errorMessage"
where you can use "contentType" to get if it is a json and parse "bodyData" accordinly
]]
end
-- dummy example to get something
local httpClientRequest = HttpClientRequest()
local url = "https://myapi.mydomain.com"
httpClientRequest:get(url, requestCallback)
-- dummy example to post something
local url = "https://myapi.mydomain.com"
local token = "abcdef123456789"
local data = "I want to post something"
local fields = {
accept = "application/json",
authorization = "Bearer " .. token
}
httpClientRequest:post(url, requestCallback, fields, data)
For usage in C++, check the pull-request
For what is this used for?
It can be used to multiple things, the main usage is to make integration to API services, like:
- chatgpt api, to generate and make things dinamically in game.
- monitoring services: you can post data to a monitoring service
- discord API: send things that is happening on realtime to your discord server
Hope you enjoy