Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Api in Nexus

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use Api in Nexus? Many novices are not very clear about this. In order to help you solve this problem, the following small series will explain it in detail for everyone. Those who have this need can come to learn. I hope you can gain something.

premise preparation

Prepare a working Nexus, here version 3.2.1

API mechanism

This article introduces the design idea of Api at the beginning of Nexus3 launch, mainly through the combination of groovy scripts to complete related functions, simply speaking, users need to provide groovy scripts, nexus provides the interface to upload and run scripts, although some rough, but most of the functions are reserved for users to use, powerful groovy scripts As for what kind of functions need to be implemented, it depends on the user's own needs. To some extent, it is an API that can create APIs.

using step

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

The format is roughly as follows:

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

Notes:

Note the use of double quotes and single quotes

The name of the script will become part of the subsequent API, please pay attention to the naming

Step 2: Upload the json file

Use the following methods and interfaces to upload json files containing groovy operations

Interface: /service/siesta/rest/v1/script

Method: POST

File: Pass in the file prepared in step 1 as POST content

Step 3: Execute groovy file

The groovy script uploaded in step 2 can be executed using interfaces such as

Interface: /service/siesta/rest/v1/script/script name/run

Method: POST

Note here that script names are also part of the execution interface, and naming becomes very important.

uses examples

Here is a demonstration of how to create a repository of type Raw in Nexus using the above method.

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

Because creating a repository requires specifying a blob, if not specified, default will be used, but if there are many projects, default will be very large. In the previous introduction to the practice of using nexus, it is also given to create your own blob for different repositories, so 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 itself is not a very complete way, it is recommended that the process of using such as rawrepotest1 is all consistent, so that the relationship between blob and repository is also relatively clear, just upload a few more json files whose size can be ignored.

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.jsonliumiaocn:~ liumiao$

Step 3: Execute 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$

results confirm

blob confirmation

The corresponding blob has been generated: rawrepotest1

repository confirmation

The repository of the corresponding raw mode has been generated: rawrepotest1

Did reading the above help you? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report