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

Detailed explanation of Angular data binding and its implementation

Table of contents Preface What is data binding? T...

js+Html to realize table editable operation

This article shares the specific code of js+Html ...

VUE implements token login verification

This article example shares the specific code of ...

Html+css to achieve pure text and buttons with icons

This article summarizes the implementation method...

Tips for using the docker inspect command

Description and Introduction Docker inspect is a ...

How to generate Vue user interface by dragging and dropping

Table of contents Preface 1. Technical Principle ...

How to build lnmp environment in docker

Create a project directory mkdir php Create the f...

Detailed explanation of single-row function code of date type in MySQL

Date-type single-row functions in MySQL: CURDATE(...

How to install the graphical interface in Linux

1. Linux installation (root user operation) 1. In...

Rsync+crontab regular synchronization backup under centos7

Recently, I want to regularly back up important i...

Why MySQL should avoid large transactions and how to solve them

What is a big deal? Transactions that run for a l...

Detailed explanation of HTML programming tags and document structure

The purpose of using HTML to mark up content is t...

XHTML introductory tutorial: Application of table tags

<br />Table is an awkward tag in XHTML, so y...

JS version of the picture magnifying glass effect

This article shares the specific code of JS to ac...