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

I am using Sonatype Nexus REST core api to get repositories.

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

In the docs, I see that the return type can be application/json

. But I am completely free to fix it.

+3


source to share


1 answer


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

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

      

which will give you formatted XML output. To get the same in JSON format, you simply edit the HTTP request header like this



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

      

Potentially you want to add credentials and specify the content type (especially if you are sending the JSON download as part of the request). You can also go to POST ..

curl -X GET -u admin:admin123 -H "Accept: application/json" -H "Content-Type: application/json" http://localhost:8081/nexus/service/local/repositories

      

+7


source







All Articles