HeaderParam Annotation In Jersey

In this tutorial we will see @headerparam example in jersey . if you are new in restful webservice then i will recommended to you first read jersey web service example . Now we will learn how to get value from Header in Jersey . If we want to send any information in header request then we get value of header by using @HeaderParam annotation. There is a example how to use @HeaderParam Annotation in jesery

import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

@Path("/user")
public class UserHander {

@POST
public Response addUser(@HeaderParam("token") String token) {
System.out.println("token=" + token);
return Response.status(Status.OK).entity(token).build();
}

}

When we send request we will set value of token parameter in header . You can send authentication data in header like auth token etc. in you rest api call. This article is a part of jersey in java tutorial where you can see more jersey restful web service example.

Leave a Reply

Your email address will not be published. Required fields are marked *

77 + = 78