Module:Apitest: Difference between revisions

From RetroMC
Jump to navigation Jump to search
(fixed typo)
(another test of possible included functionality)
Line 3: Line 3:




local http = require('http') -- Load the HTTP library
local http = require("socket.http") -- Load the HTTP library
local json = require("json")


function p.getRandomFact()
function p.getRandomFact()
Line 11: Line 12:


   if status == 200 then
   if status == 200 then
     local factData = mw.test.jsonDecode(response)
     local factData = json.decode(response)
     return factData.value
     return factData.value



Revision as of 21:35, 25 March 2024

Documentation for this module may be created at Module:Apitest/doc





local http = require("socket.http") -- Load the HTTP library
local json = require("json")

function p.getRandomFact()
   local apiUrl = 'https://catfact.ninja/fact'
   local response, status = http.reguest(apiUrl)


   if status == 200 then
    local factData = json.decode(response)
    return factData.value

   else
    return 'Request Failed either the API is Down or the site ran into a unknown error please try again later'
   end
end

return p