The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Joel Suter
August 21, 2017

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Hasnae
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 26, 2017

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

TAGS
AUG Leaders

Atlassian Community Events