Module:Apitest

From RetroMC
Revision as of 21:51, 25 March 2024 by Thecow275 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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



local p = {}


function p.getRandomFact()
   local apiUrl = 'https://catfact.ninja/fact'
   local response, status, headers = mw.fetchUrl(apiUrl)


   if status == 200 then
    local success, factData = pcall(mw.text.jsonDecode, response)
    if success and factData and factData.fact then
     return factData.fact
   else
     return 'Invalid API Response'
    end
   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