I'm an author and a developer focused on build tools. I'm currently focusing on Gradle, but I have an interest in all build tools and most development infrastructure. I focus on Enterprise Java, Ruby, and the interface between Systems Administration and Software Development. The focus of my work is to make it easier for individuals to adopt open source software. Tim is a DZone MVB and is not an employee of DZone and has posted 41 posts at DZone. You can read more from them at their website. View Full User Profile

Learning the Nexus REST API: Read the Docs or Fire Up a Browser

07.25.2012
| 3779 views |
  • submit to reddit
When you use Nexus, it is more than a UI. It is a collection of services available for you to automate. With these services you can integrate Nexus in whatever workflow makes sense for you. As a developer, this is what I look for in a product: something beyond the UI, something I can automate, and, most importantly, something that is documented. In Nexus, we’ve made it easy to start integrating Nexus REST services into your workflow by providing extensive documentation.

Yesterday’s post was all about automating Nexus with REST services, and today’s post is focused on giving you the tools you need to access the hundreds of REST endpoints you have access to with Nexus. If you are trying to automate anything in Nexus, you should know that there are two ways to “read” the Nexus REST API. You can access plugin documentation via the Nexus UI, or you can use a tool like Firebug in Firefox or Chrome’s Developer Tools and inspect the requests generated by the Nexus UI.

Reading the Nexus REST Documentation

While Nexus has a rich set of hundreds of REST endpoints for everything from core actions like storing artifacts in a repository to professional features like procurement and staging, the documentation is little tough to find. Here are the steps you need to take to access this documentation:

  1. Login as an Administrator
  2. In the Administration section of the left-hand menu, click on Plugin Console to open the Plugin Console.
  3. Once in the Plugin Console you will see a list of Nexus Plugins. Click on a plugin to view the APIs it provides.
  4. Once you select a plugin, you should see a list of APIs. For example, the video below shows the Core API, click on the link in the Plugin Console to view the REST API documentation.

Here’s a video walkthrough that shows you how to get to the Nexus REST documentation:

 

 

The REST API documentation is extensive and detailed, but there are often times when the best documentation for the Nexus REST API is Nexus itself. In these cases, fire up one of several modern browsers and just watch the network traffic…

Learning the Nexus API by Example

Nexus is a lightweight Javascript UI that connects to REST endpoints on the server-side. Unlike other repositories, the bulk of our application’s UI logic happens in your browser. We don’t do a round-trip to the server and ask for HTML, Nexus uses ExtJS and is communicating to these REST endpoints and exchanging JSON.

For us the REST API isn’t just an extra feature that is “nice” to have, the Nexus UI is based on this REST API. Consider it solid and tested, we rely on it as much as you will come to rely on it. Everything you do in the Nexus UI is calling back to this API. This is why the best way to figure out how to interact with the Nexus REST API is often just fire up a tool like Chrome and watch what the UI is sending across the wire back to Nexus.

Here’s a video that demonstrates how to use Chrome to spy on Nexus. This is often the fastest way to figure what your automation scripts need to do to automate common Nexus tasks:

 

 

Published at DZone with permission of Tim O'brien, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)