Nexus uses API to operate

Nexus uses API to operate

Nexus provides RestApi, but some APIs still need to be combined with Groovy to operate. It has been enhanced in versions 3.3 and later, but it still has some "usage features" compared to ordinary RestApi. This article takes the creation of a raw repository as an example to confirm the relevant usage methods.

Prerequisites

Prepare a working Nexus, here is version 3.2.1

API mechanism

This article introduces the design ideas of the API when Nexus 3 was first launched. It mainly uses groovy scripts to complete related functions. In short, users need to provide groovy scripts by themselves, and nexus provides an interface for uploading and running scripts. Although it is a bit rough, most of the functions are left for users to use. As for what kind of functions need to be implemented in the powerful groovy script, it depends on the user's own needs. To a certain extent, it is an API that can create APIs

How to use

Step 1: Create a runnable groovy script using the json file as a carrier

The format is roughly as follows:

{
 "name": "Script name",
 "type": "groovy",
 "content": "groovy statement"
}

Note:

  • Note the use of double quotes and single quotes
  • The name of the script will become part of the subsequent API, so please pay attention to the naming.

Step 2: Upload the json file

Use the following method and interface to upload the corresponding json file containing groovy operations

  • Interface: /service/siesta/rest/v1/script
  • Method: POST
  • File: Pass the file prepared in step 1 as the content of POST

Step 3: Execute the groovy file

Use the following interface to execute the groovy script uploaded in step 2:

  • Interface: /service/siesta/rest/v1/script/script name/run
  • Method: POST

It is important to note that the script name will also be part of the execution interface, so naming becomes very important.

Usage Examples

The above method is used here to demonstrate how to create a Raw type repository in Nexus.

Step 1: Create a runnable groovy script using the json file as a carrier

Because you need to specify a blob when creating a repository, if you don't specify it, the default will be used. However, if there are many projects, the default will be very large. In the previous introduction to the use of nexus, it was also given to create your own blob for different repositories, so here create the following json file:

liumiaocn:~ liumiao$ cat rawrepotest1.json 
{
 "name": "rawrepotest1",
 "type": "groovy",
 "content": "def rawStore = blobStore.createFileBlobStore('rawrepotest1', 'raw'); repository.createRawHosted('rawrepotest1', rawStore.name);"
}
liumiaocn:~ liumiao$

Suggestion: Because this way of using Nexus is not a very complete method, it is recommended to use it in the same way as rawrepotest1, so that the relationship between blob and repository is clearer. It is nothing more than uploading a few more json files of negligible size.

Step 2: Upload the json file

liumiaocn:~ liumiao$ curl -X POST -u admin:admin123 --header "Content-Type: application/json" http://localhost:32004/service/siesta/rest/v1/script -d @rawrepotest1.json
liumiaocn:~ liumiao$

Step 3: Execute the groovy file

liumiaocn:~ liumiao$ curl -X POST -u admin:admin123 --header "Content-Type: text/plain" http://localhost:32004/service/siesta/rest/v1/script/rawrepotest1/run
{
 "name" : "rawrepotest1",
 "result" : "RepositoryImpl$$EnhancerByGuice$$13e8178d{type=hosted, format=raw, name='rawrepotest1'}"
}liumiaocn:~ liumiao$

Result Confirmation

Blob confirmation

The corresponding blob has been generated: rawrepotest1

repository confirmation

The corresponding raw repository has been generated: rawrepotest1

summary

Combining Nexus with groovy can achieve API integration, but this method still has many invariants in use. Whether errors occur during multiple executions has become a matter for the groovy script to confirm. Whether the relevant functions will be enhanced may depend on the support of subsequent versions of Nexus. Whether the combination with groovy will be the corresponding method during the functional transition period still needs further observation.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Detailed explanation of common command configuration of idea maven nexus
  • How to publish Maven project (jar package) to Nexus private server
  • Maven detailed tutorial on how to package and upload the project to nexus private server
  • Detailed explanation of sample code for springboot~nexus project packaging
  • How to use Nexus to build a Maven private server
  • Getting started with Maven: Using Nexus to build a Maven private server and upload and download jar packages
  • How to use nexus to build a Maven private server and idea in a local area network
  • Detailed steps for setting up a nexus server
  • Nexus installation and configuration graphic tutorial

<<:  Centos6.9 installation Mysql5.7.18 step record

>>:  Implementation of code optimization for Vue2.x project performance optimization

Recommend

This article helps you understand PReact10.5.13 source code

Table of contents render.js part create-context.j...

VUE introduces the implementation of using G2 charts

Table of contents About G2 Chart use Complete cod...

How to use webpack and rollup to package component libraries

Preface I made a loading style component before. ...

Tomcat parses XML and creates objects through reflection

The following example code introduces the princip...

Example of converting spark rdd to dataframe and writing it into mysql

Dataframe is a new API introduced in Spark 1.3.0,...

Use IISMonitor to monitor web pages and automatically restart IIS

Table of contents 1. Tool Introduction 2. Workflo...

vsCode generates vue templates with one click

1. Use the shortcut Ctrl + Shift + P to call out ...

How to configure nginx+php+mysql in docker

First, understand a method: Entering a Docker con...

Docker container log analysis

View container logs First, use docker run -it --r...

HTML Basics: HTML Content Details

Let's start with the body: When viewing a web ...