Grails a Web open source framework for rapid development

Source: Internet
Author: User
Keywords Grails open source framework
Tags api class client data data model design developers development

This article describes a more general encapsulation scenario in which dojo is used in combination. Stateful, DOJO.XHR, Dojo. Common classes and methods such as Deferred enable developers to implement synchronous or asynchronous interactions between client and REST-style APIs in an object-oriented, simple and transparent manner.

This article will use Dojo 1.7 and follow AMD's specifications to design and implement the Web front-end http://www.aliyun.com/zixun/aggregation/14208.html "> data model that interacts with the REST API."

Preparatory work

Installing Grails

Download 2.0.1 920.html ">release version at the Grails official site

Preparing the REST API

Grails is a fast-growing web open source framework that quickly implements the REST API you need to implement the code in the annex to this article:

Table 1.REST APIs and their support HTTP methods

API Get POST put delete/shape√/circle√√/circle/${id}√√√/square√√/square/${id}√√√

Using Dojo

This article will use CDN based Dojo1.7.2, and developers who are limited by the network conditions can download the Dojo1.7.2 release version at the Dojo official site.

Define the WEB-side data model and use

Geometric shapes are often used in tutorials related to object-oriented programming, and this article is no exception. The following is a UML diagram of base class Shape, subclass Circle, and Square:

Figure 1.UML Object diagram

In general, this design idea is commonplace in the back-end domain, but it also applies to the front-end, especially the OPOA (one Page one creator) project with more data objects. Based on the REST API features, AJAX code that interacts with the backend API is encapsulated in the Resource class method, and the subclass simply declares its resource name. Even if the backend API is not restful, the parent class method can be overridden in subclasses to meet a variety of requirements. This type of data encapsulation can be achieved through a variety of mainstream front-end framework, once adopted, can greatly simplify the work of front-end workers. The use of Dojo1.7 above version, the module loading, class mechanism and asynchronous programming has a unique advantage, will continue to elaborate later.

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.