Building rich Java Web applications using Apache wink and Ajax

Source: Internet
Author: User
Tags json require web services java web

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.