Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Add parameters to REST call

Justin Carr February 10, 2014

I'm sure this is somewhat easy, but I couldn't figure it with my limited Java knowledge, and couldn't find an answer.

I have a plugin that implements some REST. I can currently get static information by going to this url:

http://my.server.com:7990/rest/my_plugin/1.0/settings

Which spits out the static info I've put in nicely.

What I want to be able to do is pass in some info, and have the plugin mutate the REST Call based on paramaters recieved, as such:

http://my.server.com:7990/rest/my_plugin/1.0/settings?repo=myrepo&project=project1

Where it will then use project and repo as variables at the Java level.

(This is specifically for Stash, but I presume the method is the same regardless)

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 10, 2014

Hi Justin,

Yep, we just use normal Jersey annotations, and they should work across all Atlassian products.

Off topic slightly, if you want to use those two parameters to load a repository from the RepositoryService, you can do the following to save you work:

@Path(ResourcePatterns.REPOSITORY_URI + "/settings")
public class SomethingResource {
    @GET
    public Response getMesssage(@Context Repository repository) {...}
}

This will end up as:

/rest/my_plugin/1.0/projects/project1/repos/myrepo/settings

Just a convention we use to make things easier. The "magic" is that you must use REPOSITORY_URI somewhere in the path, otherwise @Context won't work. Using query parameters is fine too though. :)

Charles

0 votes
Justin Carr February 10, 2014

Incase anyone else has the same question:

@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getMessage(@QueryParam("repo") String repo, @QueryParam("project") String project)

TAGS
AUG Leaders

Atlassian Community Events