This article describes the Apache Wink, demonstrates how to install it, and comes with a simple RESTful Web service that manages the list of tasks. The example in this article is based on the Bookmarks example that is carried by the Apache Wink release. However, the examples in this article use different message formats to enrich the user experience by using asynchronous JavaScript + XML (Ajax) to easily invoke from a Web page.
REST and Ajax
RESTful Web services are exposed by using a URL structure and provide a simplified interface for creating, reading, updating, and Deleting (CRUD) operations on Web services. RESTful Web Services can use and provide messages in various formats that can be identified by the multipurpose Internet Mail Extensions (MIME) type, including JavaScript Object notation ( JSON), XML, and other binary data.
The simplicity of RESTful Web Services makes access to web client technologies such as Ajax easier. The ability to use JSON as a message format further simplifies the interaction.
REST
Unlike SOAP, the RESTful Web service does not necessarily require an XML document as a message carrier. There is no standard XML Schema Definition (XSD) Description message format. This allows the RESTful Web service to be as simple as the document returned when the URL is accessed. In fact, the Web page does conform to the configuration file for the RESTful Web service.
Because the message format does not require the use of XML, almost all types of message content are supported. For example, you can submit plain text to a URL to invoke the POST method on a RESTful Web service. You can also use other simple message formats, such as JSON. Apache Wink can match the MIME types recognized in HTTP operations and service methods that use and provide a given MIME type.
The RESTful Web service exposes services using different HTTP operations, and these services perform different operations. Although there is no established standard for itself, there are some principles that define which HTTP operations are used for specific tasks. Take a look at table 1.
Table 1. REST Operations and URLs sample
HTTP operations |
URL sample |
Use |
Get |
Http://localhost:8080/Task/rest/tasks |
Enumerate all the tasks that a service searches for |
Get |
http://localhost:8080/task/rest/tasks/1</td> |
Get a task with ID 1 |
POST |
Http://localhost:8080/Task/rest/tasks |
Create a new task based on the submitted data |
Put |
http://localhost:8080/task/rest/tasks/1</td> |
To update a specified task with ID 1 using a data request |
DELETE |
Http://localhost:8080/Task/rest/tasks/1 |
Delete a task with ID 1 |