Dite Gashi
Dite Gashi

Reputation: 128

Simple POST request to Java Web Service

I have created a RestfulWeb Service in Java that is working well with GET requests. However I cannot find some good resource on how to make it accept POST requests.

This is how I run GET

@Path("/hello")
public class Hello {

    @GET
    @Path(value = "/ids/{id}")
    public String ids(@PathParam(value = "id") final String id) throws JSONException {
        return getResults("select * from " + id);
    }

In order to access this method from web I just go to mywebservice.com/hello/thisismyID and the method receives the "ID".

How would this look if it was to be done with a POST.

Thanks in advance,

-D

Upvotes: 0

Views: 4643

Answers (2)

MariuszS
MariuszS

Reputation: 31567

Example

@Path("/hello")
public class Hello {

    @POST
    @Path(value = "/ids")
    public String ids(@HeaderParam("id") final String id) throws JSONException {
        return getResults("select * from " + id);
    }
}

Upvotes: 1

sschrass
sschrass

Reputation: 7166

@Path("/hello")
public class Hello {

    @POST
    @Path("/ids/{id}")
    public String ids(@PathParam("id") final String id) throws JSONException {
        return getResults("select * from " + id);
    }
}

an exhaustive tutorial can be found here: Vogella_REST

Upvotes: 1

Related Questions