How to get a POST parameter in REST application

2

I started a Rest application and I have a createPost java class

    POST
    @Path("/post/")
    @Produces(MediaType.APPLICATION_JSON)
    public static String createPost(@FormParam("loopID") String loopID) throws IOException {
         ConnectDAO dao = ConnectDAO();
         Post post = new Post();
         post.setLoopId(loopID);
    }

Where it will receive this value by parameter.

In javascript I have to create a service since I use angular called createPost, and it will do the "POST".

createPost: function(loopID) {
            if (!loopID) {
                hyatt.ui.view.alert('There is no file to upload. Please choose a file.');
            } else {
                return http({
                    method: 'POST',
                    url: url + '/post/',
                    headers: {
                        'Content-Type': undefined
                    },
                    transformRequest: formData
                });
            }
            // This forces the break of execution.
            throw new Error('The UploadService service needs a file and this file cannot be a video');


        },

Above I'm getting by parameter the value I want to pass to JAVA. How can I be doing this? I tried with @FormParam but it did not work out.

Note: I can not currently get via @PathParam since the url calls an external service.

Who can help thank you.

    
asked by anonymous 27.01.2015 / 21:46

1 answer

1

Try this.

@POST
@Path("/post/")
@Produces("application/json ; charset=UTF-8")
public String createPost(String loopId){
    ConnectDAO dao = ConnectDAO();
    Post post = new Post();
    post.setLoopId(loopID);
    return "";
}
    
27.01.2015 / 22:04