For our DevOps, CD, and Deployment teams, we’ve seriously improved search capabilities for the latest version of components! As you may know, there are 3 REST endpoints in NXRM 3 that are used for searching:
(serverUrl)/service/rest/v1/search - search for components
(serverUrl)/service/rest/v1/search/assets - search for assets
(serverUrl)/service/rest/v1/search/assets/download - search for an asset and download it
As of 3.16, each of these endpoints support a few new query parameters:
sort - this query parameter will define how to sort the search results. As an added bonus, for the search-and-download endpoint, this removes the requirement that only 1 result is returned in the search, simply letting you download the first result. If this parameter is omitted the default relevance sorting will be used. The following fields can be sorted on:
group
name
version
repository
direction - the order to sort the results in; this field is ignored if the sort field is not also supplied. The direction can either be ‘asc’ (ascending) or ‘desc’ (descending). If this field is omitted, default direction of ‘asc’ will be used, unless sorting on version then ‘desc’ will be used.
prerelease - a flag stating whether to include prelease assets in the response. If set to ‘true’ only prerelease results will be returned. If set to ‘false’ only release results will be returned. If this field is omitted, the default behavior of returning both release and prerelease results will be used.
Note that currently only the maven/npm/yum formats properly populate this ‘prerelease’ field in the search index, other formats have all assets marked as ‘release’.
When these query parameters are combined, they give the ability to download the latest release version of an asset, which has been something often requested in NXRM 3. Downloading the latest junit for example:
Hi Max,
Were you aware of our GUI API?
It’s designed to answer questions like this.
See attached, for the location in the UI, as well as the download section expanded.
When you fill in your variables it’ll give a sample curl like curl -X GET “http://localhost:8081/service/rest/v1/search/assets/download?sort=version&name=jtzapp&version=1.0” -H “accept: application/json”. Really it depends what you want to do, and you can adjust from there once you have a sample that works for you.
I hope that helps vaguely=)
Best,
Joe
Version of Nexus is: Sonatype Nexus Repository ManagerOSS 3.17.0-01
Command: curl -v -u xxx:xxx "http://localhost:8080/service/rest/v1/search/assets/download?sort=version&direction=desc&repository=maven-snapshots&maven.groupId=bla.bla.bla&maven.artifactId=bla-bla&maven.extension=tar.gz"
It runs in a Docker container (‘sonatype/nexus3’). Tried same curl command within the container with no luck either.
Curl verbose output:
* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'xxx'
> GET /service/rest/v1/search/assets/download?sort=version&direction=desc&repository=maven-snapshots&maven.groupId=bla.bla.bla&maven.artifactId=bla-bla&maven.extension=tar.gz HTTP/1.1
> Authorization: Basic xxx
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Sun, 14 Jul 2019 17:33:23 GMT
< Server: Nexus/3.17.0-01 (OSS)
< X-Content-Type-Options: nosniff
< Location: http://localhost:8080/repository/maven-snapshots/bla/bla/bla/bla-assemblies/x.y.z-SNAPSHOT/bla-assemblies-x.x.x-20190712.105616-6-linux.tar.gz
< Content-Length: 0
<
* Connection #0 to host localhost left intact
But doesn’t do any actual downloading. As mentioned before: the URL used with the curl command works using a (Chrome) browser.
Search on assets without download option, does work as expected:
curl -v -u xxx:xxx "http://localhost:8080/service/rest/v1/search/assets?sort=version&direction=desc&repository=maven-snapshots&maven.groupId=bla.bla.bla&maven.artifactId=bla-bla&maven.extension=tar.gz"
* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'xxx'
> GET /service/rest/v1/search/assets?sort=version&direction=desc&repository=maven-snapshots&maven.groupId=bla.bla.bla&maven.artifactId=bla-bla&maven.extension=tar.gz HTTP/1.1
> Authorization: Basic xxx
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 14 Jul 2019 17:38:40 GMT
< Server: Nexus/3.17.0-01 (OSS)
< X-Content-Type-Options: nosniff
< Content-Type: application/json
< Content-Length: 636
<
{
"items" : [ {
"downloadUrl" : "http://localhost:8080/repository/maven-snapshots/bla/bla/bla/bla-assemblies/x.y.z-SNAPSHOT/bla-assemblies-x.y.z-20190712.105616-6-linux.tar.gz",
"path" : "bla/bla/bla/bla-assemblies/x.y.z-SNAPSHOT/bla-assemblies-x.y.z-20190712.105616-6-linux.tar.gz",
"id" : "xxxxxxxxxx",
"repository" : "maven-snapshots",
"format" : "maven2",
"checksum" : {
"sha1" : "xxxx",
"md5" : "xxxx"
}
} ],
"continuationToken" : null
* Connection #0 to host localhost left intact
}
Thanks. I ignored 74 [visit count] still my afternoon url didnt work. I ve tried, the Swagger - try it option. It was printing ascii characters, and then I copied url to unix shell and prefixed a wget, but no success.
I was also not sure of attributes - name vs maven.artifactId, format as maven2, so many probabilities.
My version is a snapshot, so removed prerelease=false, as I was getting a message like - no assets found…
My requirement - Get latest snapshot
Note: I specified one property[ dont remember now] to a value - jar, as I want the jar artifact
When I add a maven.classifier= to my url, it does not slim down the results to items with no classifier as the documentation says it should. I’m running Nexus v3.16.1 right now.