Overview of the WADL structure

The WADL schema that you use for building a WADL file is based on the WADL specification (https://www.w3.org/Submission/wadl/). Here is a quick overview of the WADL file content that describes the RESTful web APIs:

The top-level element in a WADL document is application. It contains global information about RESTful web services, such as links to the schema definition and documentation. Here is a quick summary of the elements that you'll see in WADL:

  • <resources>: This element comes as wrapper for all the resources exposed by a RESTful web application. The base attribute for the resources identifies the base path of all the resources in the API.
  • <grammars>: This element includes the definition of data formats using  the <include> element, which references the data format with the href attribute. 
  • <resource>: This element appears as a child of the <resources> element. It is used for describing a set of resources, each identified by a URI. This element can optionally have <param> to describe the path parameters present in the request if any.
  • <method>: A resource may have one or more <method> definitions. This element defines the HTTP methods, such as GET, POST, PUT, and DELETE, available to the resource with the relevant request and response elements. Note that the presence of this element in WADL represents a REST resource method in a RESTful web service.
  • <request>: A <method> definition can optionally include this element, which describes an input to the resource method. A request can have one or more of the following elements as its child:
    • <doc>: This element is used for documenting the parameters
    • <representation>: This element specifies the internet media type for the payload present in the body of the request
    • <param>: This element specifies the query or header parameter present in the request
  • <response>: This element specifies the result of invoking an HTTP method on a resource. The optional status code present in the response describes the list of the HTTP status codes associated with the response. A response can have one or more of the following elements as its child:
    • <doc>: This element is used for documenting the <response> header parameters
    • <representation>: This element describes the internet media type for the response content returned by the API
    • <param>: This element specifies the HTTP header parameters present in the response
To learn more about the WADL specification, visit http://www.w3.org/Submission/wadl.

Let's take a look at a simple WADL example before proceeding further. See the following code snippet. This method returns a Department object for the department ID passed by the client:

@GET 
@Path("{id}") 
@Produces("application/json") 
public Department findDepartment(@PathParam("id")  
    Short id){ 
    //Method body is omitted for brevity 
} 

Wondering how the preceding REST API can be described in WADL? The following WADL code answers this question. You do not need to spend much time on understanding this WADL file structure at this point of time. We will discuss the generation of WADL from the JAX-RS resource class in detail later:

<application xmlns="http://wadl.dev.java.net/2009/02"> 
<doc xmlns:jersey="http://jersey.java.net/" 
jersey:generatedBy="Jersey: 2.10.4 2014-08-08 15:09:00"/> <grammars/> <resources base= "http://localhost:8080/hrapp/webresources/"> <resource path="{id}"> <param xmlns:xs="http://www.w3.org/2001/XMLSchema"
name="id" style="template" type="xs:short"/> <method id="findDepartment" name="GET"> <response> <ns2:representation xmlns:ns2=
"http://wadl.dev.java.net/2009/02"
xmlns="" element="department"
mediaType="application/json"/> </response> </method> </resource> </resources> </application>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.237.29