Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get results from Sonatype Nexus REST API in JSON format

Tags:

json

rest

api

nexus

I'm using Sonatype Nexus REST core api to get repositories.

The output format is XML. How can I get the output in JSON format?

I can see in the docs that the return type can be application/json. But I am completely in blank where to set this.

like image 399
webExplorer Avatar asked Oct 14 '14 16:10

webExplorer


People also ask

How do I get JSON from a REST API?

To receive JSON from a REST API endpoint, you must send an HTTP GET request to the REST API server and provide an Accept: application/json request header. The Accept header tells the REST API server that the API client expects JSON. In this REST API GET example, we make a GET request to the ReqBin echo REST API endpoint.

How do I get JSON from an API endpoint?

How do I get JSON from a REST API endpoint? To receive JSON from a REST API endpoint, you must send an HTTP GET request to the REST API server and provide an Accept: application/json request header. The Accept header tells the REST API server that the API client expects JSON.

What are the advantages of Sonatype Nexus?

One of the advantages Sonatype Nexus has is that a large portion of our codebase is Open Source Software. You can checkout nexus-oss from Github, open the project in an IDE and find out how the endpoints are defined, including what arguments and payloads are accepted.

Is there a video for automation of Nexus with REST API?

Manfred Moser has created a quick 7 minute video that walks through the automation of Nexus with the REST API. This is one module in our free training series. Become a member of TheNEXUS Community and watch the rest of them.


1 Answers

As an example with curl here is a call to get the list of repositories

curl http://localhost:8081/nexus/service/local/repositories

which will give you xml formatted output. To get the same in JSON format you just edit the HTTP header of the request like so

curl -H "Accept: application/json" http://localhost:8081/nexus/service/local/repositories

Potentially you want to add credentials and specify the content type as well (especially if you are posting JSON load as part of the request). You can also change to a POST..

curl -X GET -u admin:admin123 -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:8081/nexus/service/local/repositories
like image 113
Manfred Moser Avatar answered Nov 15 '22 03:11

Manfred Moser