Tag Archives: rest

You Don’t Need A Browser to Use Maven Central


June 9, 2011 By Joel Orlina

Since its release in January, the Maven Central website (http://search.maven.org) has provided Apache Maven users with:

  • Search functionality that allows one to quickly track down artifacts and their dependency details when trying to resolve build problems.
  • Browse functionality that aids in discovery of new artifacts to use in projects.

In the intervening months, Sonatype has focused its efforts on improving the usability of the Maven Central user interface in the hopes of making it the first place users look when trying to find an artifact.  Recently, users who have reaped the benefits of using the Maven Central website have asked about interacting programmatically with the search functionality.

If you pay attention to your web browser’s address bar when conducting searches on Maven Central, you can already see that a REST-style API exists.  For example, searching for “guice” from the main search box results in the following URL being generated (the following URL’s are NOT URL-encoded for the sake of readability):

Translating the search request into English, that URL requests a basic search for any artifact (irrespective of version) containing the word “guice” in either the groupId or artifactId, returning only the first page of results.  Each row of the results shows the latest version of the artifact and the date the artifact was last updated as well as any classifiers associated with the artifact.

You can build up the complete library of search requests simply by paying attention to your web browser’s address field as you use the Maven Central website.  For the sake of convenience, we’ve collected all the URLs that make up Maven Central’s search API in a document available here.

Sadly, these URL’s are still only useful when requesting them via web browser.  They are links that can be bookmarked or e-mailed, but they do NOT work when using a non-browser agent like wget or curl.  The Maven Central user interface is essentially a browser-based application that uses Javascript to make asynchronous requests to yet another set of URL’s.  Once you make a request that looks like the URL above, the browser fires off the actual request to another Maven Central URL responsible for conducting the search and returning results that are formatted by the browser.

The sample request above, when converted to an actual Maven Central search request, looks like this:

The actual text of your query goes in the appropriately named “q” parameter, the “rows” parameter restricts the results to a smaller number than the full result set, and the “wt” parameter can be either “xml” or “json,” depending on how your application prefers to handle results.

Some useful examples appear below.  Again, please refer to the API Guide for a complete listing:

In an upcoming post, I’ll describe the architecture behind Maven Central that makes all this functionality possible.

Taking Repos Offline/Online via the Nexus REST API


April 22, 2010 By Tim O'Brien

This post runs through a simple Ruby script that manipulates the offline/online status of hosted Nexus repositories. Such a script would be useful if you need to manipulate the storage of a repository while Nexus is running. Assume you have a script that needs to backup the storage directory of all of your hosted directories once a night. If you wanted to make sure that your repository isn’t altered in the middle of a backup, you would put each hosted repository out of service before the backup job ran. After the job completed, you would put all of your hosted servers back into service.

While you could do this via the Nexus UI, this wouldn’t help your automated nightly backup script. For this script to be easy to run, you’ll need to script Nexus via the REST interface. With the Nexus 1.6 release, we’ve released full documentation of the Nexus REST services available in every Nexus installation (REST doc). Continue reading for an example of how to interact with, authenticate, and manipulate a Nexus instance via the REST APIs. Continue reading

Documenting the Nexus REST API with Enunciate


February 8, 2010 By Tamas Cservenak

Nexus OSS Core has more than 120 REST Resources published. And that number is just increasing with new Nexus Plugins. Not to mention Nexus Pro that comes with even more plugins and more REST resources.    Everything you do in Nexus, whether you use the Maven Nexus plugin or the Nexus UI, is interacting with a REST service that is available to you if you want to write your own customizations and scripts.   It has been this way since we started the project in 2007.  In this post, I’m going to discuss how this came to be, how Nexus was developed with REST in mind from the beginning.

Nexus: A Core of REST Services

When we started the Nexus project, I called it a “blind” application.  A “blind” webapp is one with no UI technology whatsoever built-in.   All it publishes is a few static files, and a REST API.   All of the UI that you see in Nexus is Javascript.   Your browser executes Javascript which, in turn, interacts with a set of services.   The only presentation technology on the server side is a trivial Velocity template used to render the initial “shell” of the page. Continue reading

Searching with the Sonatype Nexus REST API: Groovy


November 21, 2008 By Tim O'Brien

This post is a follow-up to the previous post which provided some sample Ruby scripts that can be used to list repositories and search for artifacts in a Nexus instance.   Today, we’re going to see how to complete the same tasks using the Groovy scripting language.   The Groovy scripting language is a scripting language that has gained popularity due to the ease of integration with the JVM.

The following scripts are in Groovy and they can be invoked from the command line using groovy.  For example, if you want to run the QuickSearch.groovy script, you would run “groovy QuickSearch.groovy activemq” to search for artfiacts that contain the string “activemq”.   I tested these Ruby scripts using the latest Groovy 1.5.7 distribution.  Go to the Groovy page, click on Download, and download the Cross-platform Installer, this will install Groovy on your machine and also tell you what you’ll need to add to your PATH. Continue reading

Searching with the Sonatype Nexus REST API: Ruby


November 19, 2008 By Tim O'Brien

When you search for artifacts using http://repository.sonatype.org, the browser is querying the Nexus repository using a REST API.   In this post, I’m going to show you some simple Ruby scripts which you can use to search the Maven repository without loading up the Nexus web interface.  You might find these scripts more convenient and more customizable, and you should feel free to copy and modify them for your own use.

The following scripts are in Ruby and they use the REXML XML processor and the Net:HTTP library.  Both of these libraries are available in the Ruby standard library.   I tested these Ruby scripts using the latest JRuby release.  If you want to try these scripts out on your own, they will run in any standard Ruby interpreter without requiring any extra RubyGems. Continue reading