We can just type the URI and get the details or response given from REST web service.
IF we get the URI for GET request for the example app We built,
http://localhost:8080/Rest/rest/employeeservices/getemployeedetail?employeeId=1
accessing through browser will give us the output
<employee>
<dateOfJoining>01-02-2001</dateOfJoining>
<department>Sales</department>
<email>test@example.com</email>
<employeeId>675436</employeeId>
<firstName>John</firstName>
<lastName>Smith</lastName>
</employee>
but here we don't have much options.
here we get the output in xml format. But if you can remember our service implementation it produces both "xml" and "json"
=======================================================================
@Path("/")
@WebService(name="employeeService" , targetNamespace="http://localhost/cxf-rest/example")
public interface CxfRestService {
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/getemployeedetail")
public Response getEmployeeDetails(
@QueryParam("employeeId") String employeeId);
}
=======================================================================
So if we need to get the output in the json format then we need to set the few setting "Accept=application/xml"
to help to achieve all these thing we need to use http client.There are various res client applications in the web and here i will be using "Advance Rest Client " plugin in the chrome.
In Rest Client you set the values for Header , type of request and etc.
You can see all the details here.
Request header, Response Header, REST URI, type of the call, and the output - here in XML
So our service produces, both xml and json
let's change output for json.
how to do that ?
Then set the "Accept" in the header "application/json" for "json".
you can see the out in json format
====================================================================
{
firstName: "John"
lastName: "Smith"
employeeId: "675436"
email: "test@example.com"
dateOfJoining: "01-02-2001"
department: "Sales"
}
====================================================================
No comments:
Post a Comment