[MetaCPAN] GET-ing a module by name Case-Insensitively

SundaraRaman R sundaryourfriend at gmail.com
Sat Jun 20 14:46:39 GMT 2015


Hi,

I'd like to GET data on a module by its name, similar to what the
/module/Module::Name endpoint does, except I would like to be able to
specify the Module::Name as module::name or Module::name, etc. What
would the easiest way to do this be?

The usecase is, I'm hacking on the MetaCPAN Instant Answer on DuckDuckGo
(eg: https://duckduckgo.com/?q=metacpan+LWP%3A%3AUserAgent), which
currently uses the /module/Module::Name form of API call internally.
This gives the user some information about the current version of the
module, as extracted from the API. It works if the user enters the
module's name in the exactly correct case, but even a single letter
being incorrect in case (eg: LWP::Useragent) leads to no result from the
API. I'd like to change this so that it works whatever case the user
enters the module name is in.

I noticed that there is a module.name.lowercase field, and got as far as:

$ curl http://api.metacpan.org/v0/module/ -d'
{
"filter": { "bool": { "must": [ { "term": { "module.name.lowercase":
"lwp::useragent" }}, {"match": {"status": "latest"}} ] } }
}'

which seems to work, but I'm unsure on (a) whether there is a simpler
way of achieving this (b) whether the above would be sufficient to
replicate what the /module/ endpoint does i.e. reliably getting the
latest version of the module.

An additional constraint (and further reason a simpler solution would be
appreciated) is that the Instant Answers (AFAICT) support making only
GET requests (without a BODY), no POSTs. So I believe the above would
have to become a big encoded "?source" abomination if this was indeed
the simplest way to achieve this. I'm hoping that this is not the case!

Cheers,
Sundar



More information about the MetaCPAN mailing list