How to put parameters in RESTful POST with JerseyFramework Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to put parameters in RESTful POST with JerseyFramework without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Let’s assume that I have simple class:

   public class Test
    {
       @Path("/test")
       @POST
       @Produces(APPLICATION_JSON)
       @Consumes(APPLICATION_JSON)
       public TestResponse post(TestResponse request, @HeaderParam("text") String text)
       {
          return new TestResponse(request.getData());
       }
    }

and I want to test this class. So how I can param in code like this:

 Entity<TestRequest> requestEntity = Entity.entity(request, MediaType.APPLICATION_JSON);
 final TestResponse response =  target("test").request().post(requestEntity, TestResponse.class);

Answer

target("test").request().header("text", "value").post(...);

When you call request(). You get back an Invocation.Builder. You can take a look at the other methods. For the most part they all return the same Invocation.Builder, so can just chain the calls.

We are here to answer your question about How to put parameters in RESTful POST with JerseyFramework - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji