REST note (3): a standard hypermedia format: Atom

Source: Internet
Author: User
Tags iso 8601

The previous section describes one of the core elements of the REST architecture style: the hypermedia format. Although the hypermedia format is very useful, such as HTML that can be well parsed by the browser. However, HTML is not omnipotent. For example, in AJAX applications, the JSON format is obviously better than HTML. Furthermore, we use a custom hypermedia format to implement a specific field. If the consumer only needs to process a small part of the expression, although we can obtain the resource expression, then filter out the resources we need to process, but this is obviously not a good way. The Atom community has developed a popular practice.

Directory:
1. Introduction to Atom
2. Atom1.0 and RSS2.0
3. introduction to basic concepts in Atom
4. Links in Atom
5. Implementation of Atom in. Net FCL
6. Usage of Atom

  1. Introduction to Atom
Atom: Abbreviation of Atom Syndication Format. It is an XML-based hypermedia format. It provides a flexible and scalable format for interoperability, and supports data transfer between cross-platform applications due to XML-based features. It is the "Recommendation Standard" of IETF ". Atom has been widely used by Google as a popular hypermedia format. Example of an Atom format:

  

2. Atom1.0 and RSS2.0
Atom may be a bit unfamiliar, but it should be familiar with RSS. The emergence of Atom makes up for some shortcomings in RSS. Wikipedia describes the following:
1. RSS 2.0 may contain text or encoded HTML content, but it does not provide a clear distinction. In contrast, Atom provides a clear tag (that is, typed ).
2. The description label of RSS 2.0 can contain full text or abstract (although the English meaning of this label is description or abstract ). Atom provides the summary and content labels to distinguish the abstract and content, and Atom allows non-text content to be added to the summary.
3. RSS 2.0 has a variety of non-standard applications, while Atom has a unified standard, which facilitates Content Aggregation and discovery.
4. Atom has a namespace that complies with XML standards, But RSS 2.0 does not.
5. Atom uses the XML: base tag embedded in xml to indicate the relative address (URI). RSS 2.0 does not have a mechanism to distinguish the relative address from the absolute address.
6. Atom uses XML: lang embedded in xml, while RSS uses its own language tag.
7. Atom forces a unique ID for each entry, which facilitates content tracking and updating.
8. Atom 1.0 allows entries to be individually translated into documents, while RSS 2.0 only supports complete seed documents, which may produce unnecessary complexity and bandwidth consumption.
9. Atom represents time according to RFC 3339 standard (a subset of ISO 8601 standard), while RSS 2.0 does not specify a uniform time format.
10. Atom 1.0 has a MIME type registered in IANA, but the application/RSS + xml used by rss 2.0 is not registered.
11. The Atom 1.0 standard includes an XML schema, But RSS 2.0 does not.
12. Atom is an open development standard under the IETF Organization Standardization program. RSS 2.0 does not belong to any Standardization Organization and is not open to copyright.

  3. introduction to basic concepts in Atom
3.1 feed)
Atom uses a list to indicate that the data is called a feed. Partial metadata of Atom is described as follows:
Id: a permanent and unique identifier in the life cycle of a feed.
Title: The Readable title provided by the abstract
SubTitle: the source information of the feed.
Category: category of the abstract. It is specified by the Value of its term attribute. In addition, there are two optional attributes: Label and Scheme. The former indicates an understandable expression, and the latter identifies the Scheme of the classification.
Updated: The Last Update Time of the feed.
Link: Get the URI of the feed.
For more information about the abstract, see MSDN

3.2 entry)
An entry is a timestamp data entity that forms a feed. A feed contains one or more entries. Although entries are generally contained in feeds, they can all be separately used as addressable resources by consumers. The following is an Atom feed: both the feed and entry have a universal Unique identifier: uuid (Universally Unique Indentifier ).
The same parts of an entry and a feed are not described in detail. Because they are a standard format, their meaning is similar. However, an entry has a content element that does not exist in a feed. It is used to set the content of an entry.

 

  4. Links in Atom
Link is the main hypermedia control in Atom. It can be used to obtain the resource expression for consumers. Link has several important attributes:
1. rel: Describes the link relationship and context of the link semantics.
2. href: gets the resource representation URI.
3. type: Possible media types of resources
Although the link has the type attribute, Content-Type information is also contained in the HTTP header of the response returned by the server to the client. In any case, Content-Type information is always the most authoritative format returned by the server to the client. However, the type attribute in the link still makes sense. For example, if the expressions returned by the server to the client both have XML and JSON formats, the client can select an appropriate URI based on its own needs to obtain the resource expression type.

Links of The link Control:
Self: the resources required for the current feed or entry are obtained by the URI identified by href.
Via: identifies the information source of the current feed or entry
Alternate: Link to the alternative expression of the current feed or entry
Enclosure: indicates that the size of resources expressed by the URI may be relatively large.
Related: indicates that the resource indicated by href has a certain relationship with the current abstract or question.
Per-archive: The last abstract of the current feed.
Next-archive: opposite to per-archive.
In practical applications, if a client is offline and the network recovers, it obtains the latest feed and can traverse the link through the per-archive link of the hypermedia control link in the feed, in this way, you can find the most recently processed abstract information, and traverse it through next-archive. These link relationship values are registered in the IANA link relationship registry and have become a standard processing method.

 

 5. Implementation of Atom in. Net FCL
In. net FCL (FrameWork Class Library), which can be used in System. serviceModel assembly System. serviceModel. in the Syndication namespace, locate the Atom-related class of the project to create our application. Main classes include SyndicationFeed, SyndicationItem, SyndicationContent, and Atom10FeedFormatter. We use SyndicationFeed to create a feed and SyndicationItem to create an entry ). Example:

SyndicationFeed feed = new SyndicationFeed{  Title = new TextSyndicationContent("feed Tile"),  LastUpdatedTime = new DateTimeOffset(DateTime.Now),  Description = new TextSyndicationContent("feed Description Content")};feed.Authors.Add(new SyndicationPerson("aa@gmial.com", "zhanshan", "cnblogs.com"));feed.Language = "us-en";feed.Generator = "test feed";feed.Links.Add(new SyndicationLink(new Uri("http://www.cnblogs.com/tyb1222"), "via", "linkTitle", "application/Atom+xml",1000));feed.Categories.Add(new SyndicationCategory("blog"));feed.Contributors.Add(new SyndicationPerson("aa@gmial.com", "zhanshan", "cnblogs.com"));SyndicationItem item1 = new SyndicationItem("Title1",    "Microsoft may have patents, patent applications, trademarks, ...more",    new Uri("http://www.microsoft.com"))    {Summary = new TextSyndicationContent("sumary")};SyndicationItem item2 = new SyndicationItem("Title2",    "The names of actual companies and products mentioned herein may be ...more",    new Uri("http://www.microsoft.com"))    {Summary = new TextSyndicationContent("sumary")};List<SyndicationItem> syndicationItems = new List<SyndicationItem> {item1, item2};feed.Items = syndicationItems;

  

  6. Usage of Atom
Resource Creation and consumption using Atom is an ideal method. In Atom, we can link resources that cannot be in the hyper-media format to resource entries and use the <Content> src attribute to link to these resources. In the REST architecture, we can adapt to Atom to get the resource expression, and use its link hypermedia control to drive the business execution and then transfer the application status. As a standard hypermedia format recommended by IETF, Atom has been widely used in thousands of Web projects, such as Gmail.

Reference: http://zh.wikipedia.org/wiki/Atom_ (% E6 % A8 % 99% E6 % BA % 96)

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.