On 02/06/2013 01:30 PM, Brad Jorsch wrote:
-- Would fetch JSON from -- http://wikidata.org/api/query/?param1=foo%C2%B6m2=bar -- if no local handler is defined and the base URL is in a whitelist jsonObject = JSONRequest("http://wikidata.org/api/query/", { param1="foo", param2="bar" } )
No manual encoding, and URL encoding can be completely skipped if the prefix happens to match a registered local handler. An optional third parameter can pass in a table to specify the request method and other options.
Having a method with a very generic and suggestive name like "JSONRequest" that only works for one long magic value of the first parameter seems like a bad design to me.
If a whitelist is enforced, then giving this URL a symbolic name looks like a solvable problem. Alternatively, each configured API end point could be a generic object with a request method:
jsonData = JSONAPI.wikidata.request({ param1="foo", param2="bar" })
Also note it's not actually taking JSON as input, it's taking a Lua table.
Right. Can you describe why you would want to pass JSON into a method that requests JSON data from an API?
Gabriel