There’s a secret lurking in Nexus Repository Manager, a beta REST API for accessing components.
You’re probably already aware of our Provisioning API, a REST API you can use to automate the configuration of your Nexus Repository instances. Well, we’ve been busy adding REST endpoints so you can list, search, and download your components as well.
Exploring the REST API
Many REST calls are made from scripts that drive curl requests, but to make it easy to explore and understand our API, we’ve integrated Swagger. Swagger generates a browser-accessible UI interface from REST endpoints. It’s interactive, so you can fill out parameters, make REST calls and see the results right in your browser.
In Swagger, you’ll see the familiar Provisioning API endpoints:
You’ll also see our new, beta endpoints for assets and components:
Components and Assets?
Nexus Repository 3.x offers format-native support for Maven2, Docker, NuGet, npm, PyPI, RubyGems, Yum proxy, GitLFS, and Bower. Each of those formats has a different content model, but internally, we store all of that as components and assets.
An asset is a binary file of some kind, plus the associated metadata for that file. A component is a logical grouping of files. In the maven2 format, for instance, your jars, poms, src-jars, and wars are all stored as assets, with a component that represents the groupId, artifactId, and version.
In the NuGet format, which has only NuGet packages (and doesn’t have all those other asset types), each component contains one asset.
Gimme the Goods
A common use case is wanting to list all the assets in a repository. Just click on the GET action for the assets endpoint:
.. fill in the ID of the repository you’re interested in:
.. and presto, results:
If you want much more control over the results you get, look into the Search endpoint, which allows the same degree of flexibility that you have from our UI-based search feature.
You also don’t have to use Swagger, that’s just for experimentation and we expect you’ll be scripting your calls. The UI shows you the URL and curl commands to achieve the same results as the calls you made through Swagger.
How Do I Get It?
If you’re using Nexus Repository 3.3.0 or later, you already have it. Open up <your_nexus_location>/swagger-ui/ to begin exploring.
If not, download the latest version of Nexus Repository OSS for free at https://www.sonatype.com/download-oss-sonatype
More Is On The Way!
This is a beta API, and we know there’s lots more to do. On the top of our list is ordering by version, so you can easily fetch the latest version of any given component out of Nexus Repository. We’re also building a search & download endpoint so you can get the content you’re looking for with a single API call.
We suspect you’ve got other needs, though, and we’d like to hear about them! Once you’ve tried our REST API, please get in touch to tell us about your experiences.
Building an integration and wondering if other Nexus Repository users might already have solved your problem? Subscribe to our nexus-users list!
For the adventurous, we also take pull requests on our public repository.