Module:Apitest: Difference between revisions
Jump to navigation
Jump to search
(another test of possible included functionality) |
No edit summary |
||
| Line 3: | Line 3: | ||
local json = require("json") | local json = require("json") | ||
function p.getRandomFact() | function p.getRandomFact() | ||
local apiUrl = 'https://catfact.ninja/fact' | local apiUrl = 'https://catfact.ninja/fact' | ||
local response, status = http. | local response, status = mw.http.ger(apiUrl) | ||
Revision as of 21:39, 25 March 2024
Documentation for this module may be created at Module:Apitest/doc
local json = require("json")
function p.getRandomFact()
local apiUrl = 'https://catfact.ninja/fact'
local response, status = mw.http.ger(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