It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

If I add an @GET method, what is the URL to call this method?

I have a plugin with the Java class A. This class retrieves some information via the Java API and i want to access this information via the URL. The problem is, I dont know what the URL is to call the Method.

@GET
@Produces(MediaType.APPLICATION_XML)
@Path("test")
public Project getProjects() {
..........
return project;
}

What is the URL that I have to type in to call this Method and get the xml? I am running this on the localhost.

1 answer

0 votes

In your atlassian-plugin.xml you should have an entry to register your rest resources :

<rest key="my-plugin-rest-resources"
name="My Plugin Rest Resources"
path="/my-plugin"
version="1.0">
<package>my.confluence.plugin.rest</package>
</rest>

Notice the path and version parameters

Then when defining your resources as follow

@Path("/project")
public class ProjectResource {

@GET
@Path("/all")
public Response allProjects() {
...
}

}

You can access them at the following URL :

htt://localhost:8080/confluence/rest/my-plugin/1.0/project/all

The version parameter allows you to evolve your api by maintaining backwards compatibility 

<rest key="my-plugin-rest-resources"
name="My Plugin Rest Resources"
path="/my-plugin"
version="1.0">
<package>my.confluence.plugin.rest.v1</package>
</rest>
<rest key="my-plugin-rest-resources"
name="My Plugin Rest Resources"
path="/my-plugin"
version="2.0">
<package>my.confluence.plugin.rest.v2</package>
</rest>

If you want to ensure you are always using the latest api version then modify the URL as follow :

htt://localhost:8080/confluence/rest/my-plugin/latest/project/all

I have used Confluence as an example, but this should be applicable to all products AFAIK

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Atlassian supported Jenkins integration for Bitbucket Server

We’ve been building a plugin to integrate Bitbucket Server and Jenkins CI, and I’m excited to announce that our alpha is ready to download and install. It lets you seamlessly configure a Jenkins job ...

1,091 views 3 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you