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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,745 views 1 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you