Closed tomByrer closed 10 years ago
You can get match for "AngularUI Team" with http://api.jsdelivr.com/v1/jsdelivr/libraries?author=AngularUI%20Team .
Could you please allow quoting?
I'm not so sure about quotes. If you encode your input right, the current method works just fine. Quotes might open a can of worms.
Wildcard search
We haven't settled on an approach yet. Now it's just a literal match.
What sort of searches do you need? Is there need for a global search?
I hope we can leverage some existing solution. Maybe we could go with regex?
You can get match for "AngularUI Team" with http://api.jsdelivr.com/v1/jsdelivr/libraries?author=AngularUI%20Team
Oh, that works great, no need for quotes! I or someone should document this.
What sort of searches do you need? Is there need for a global search?
My use-case is to insert <script src="http://CDN/latest/lib.js">
inside editors. JSBin's [Add Library] is a great example. It would be helpful for people to search for all jQuery or Angular plugins. Perhaps not everyone knows that 'yepnope''s project name is listed as "yepnope.js" on jsDelivr but "yepnope" on CDNJS. Though I see the need to search for a perfect match for 'jquery' if they don't want to pull up every plugin.
I can also see the API being used for web front-ends, like jsDelivr.com, an all-in-one CDN search, or a JavaScript library directory. So searching for the latest Angular-UI plug-in updates or what's new from tjholowaychuk is helpful.
I got an 'Express 500 error' for http://api.jsdelivr.com/v1/jsdelivr/libraries?assets=angular-ui.min.js
.
I was looking to find the latest version for a particular file, to insert in online editors, or run from a local script to replace existing references with their latest versions on CDNs.
I hope we can leverage some existing solution. Maybe we could go with regex?
Looks like regex.test(array)
is fastest, though perhaps array.indexof(regex)
can work.
My initial impression of precompiling the regex may not be helpful; these are tight loops of the same query. Though perhaps later testing for universal precompiling, or optimizing select queries, would improve performance.
assets is an array, so you can't do it like you did. Maybe you can try this?
http://api.jsdelivr.com/v1/jsdelivr/libraries?mainfile=angular-ui.min.js
Otherwise @bebraw should explain how to pass a parameter to the array.
Also Juho added wildcard support. So you can also do this:
http://api.jsdelivr.com/v1/jsdelivr/libraries?name=yepnope*
Also Juho added wildcard support. So you can also do this:
http://api.jsdelivr.com/v1/jsdelivr/libraries?name=yepnope*
Oh cool, thanks! Unfortunately I get the empty set with http://api.jsdelivr.com/v1/cdnjs/libraries?name=yepnope*
, though yep*
works with both. I usually assume * = 0+ items.
Maybe you can try this?
http://api.jsdelivr.com/v1/jsdelivr/libraries?mainfile=angular-ui.min.js
I can, but I can't find http://api.jsdelivr.com/v1/jsdelivr/libraries/lodash?lastversion&assets=lodash.underscore.js
. I can skip this, since I can workaround it for now.
cheers
Strange, for me it works. Can you try to clear your cache?
Can you try to clear your cache?
Yes, that worked, cheers.
@tomByrer What's http://api.jsdelivr.com/v1/jsdelivr/libraries/lodash?lastversion&assets=lodash.underscore.js
supposed to return? What are you trying to do? The query doesn't look valid to me.
I think he wanted to do this
http://api.jsdelivr.com/v1/jsdelivr/libraries?fields=lastversion&assets=lodash.underscore.js
So basically get the lastversion parameter from the project that has that filename in its assets.
Yes, what he said ^ :) My use case is to help people refresh their asset URLs to the latest version. Ideally, I'd like to also search for latest in branch, just like we can grab the file for latest 1.* or latest 1.10.* files. Though I don't want to grab the entire file, just build the hardcoded URL, so webdevs can approve a specific version before pushing before production. Most devs want to test before using, so not letting them verify the version changes is a bad idea. A triggered build-tool script will help devs keep updated with little drama.
I understand if you feel my idea is out of scope. I could just get http://api.jsdelivr.com/v1/jsdelivr/libraries/lodash?fields=lastversion,assets
& build what i want from there.
I understand if you feel my idea is out of scope. I could just get http://api.jsdelivr.com/v1/jsdelivr/libraries/lodash?fields=lastversion,assets & build what i want from there.
If it's fine, maybe go with that then. It's a little bit of extra work on your side as you need to process the assets.
I'm not a fan of the current format of assets by the way. What if instead of
{
"version": "2.1.0",
"files": [
"jquery.js",
"jquery.min.js",
"jquery.min.map"
]
},
you could get something like
"2.1.0": [
"jquery.js",
"jquery.min.js",
"jquery.min.map"
]
Then you could do like
request.get('http://api.jsdelivr.com/v1/jsdelivr/libraries/lodash?fields=lastversion,assets', {json: true}, function(err, res, data) {
var files = data.assets[data.lastversion];
// operate with files now
});
Given it's a breaking change we would have to do v2. @jimaek What do you think?
@tomByrer Would this new format help you?
What other features we could get for v2?
"2.1.0": [
"jquery.js",
"jquery.min.js",
"jquery.min.map"
]
does look sexier, & I always like smaller data transfers :+1: & thanks for the example!
What other features we could get for v2?
Would it be out of scope to search for what CDN hosts a particular project? That's why I was looking for better project searching. There are many hosted on one, but not the other. Versions differ very often.
// find what React versions are hosted on all CDNs
http://api.jsdelivr.com/v2/libraries?assets=react.min.js&fields=cdn,name,versions
// new jQuery just released; who has it?
http://api.jsdelivr.com/v2/libraries?name=jquery&fields=cdn,lastversion
Would it be out of scope to search for what CDN hosts a particular project?
That could fit v2. As you suggested it could go to v2/libraries
. The question is what should that return. What would you expect?
I think it makes sense to add a cdn
field to each of your endpoints with its respective name:
http://api.jsdelivr.com/v1/jsdelivr/libraries --> all libraries have {cdn: 'jsdelivr'}
http://api.jsdelivr.com/v1/google/libraries --> all libraries have {cdn: 'google'}
http://api.jsdelivr.com/v1/cdnjs/libraries --> all libraries have {cdn: 'cdnjs'}
querying v2/libraries
will simply return the concatenated result from all three endpoints
@shahata That's one option. I sketched out another alternative at #16. Then you would get aggregate result and you could access CDN specific results directly from that.
The field searching is very useful, thanks! But it is too literal.
http://api.jsdelivr.com/v1/jsdelivr/libraries?author=angularui
gives one resulthttp://api.jsdelivr.com/v1/jsdelivr/libraries?author=AngularUI
gives anotherhttp://api.jsdelivr.com/v1/jsdelivr/libraries?author=%22AngularUI%22
does not work, so 'AngularUI Team' or can never be found. (Many people use their full name at author).