There is a design style called restful

Source: Internet
Author: User
Tags representational state transfer

Preface

I just read the Chinese version of restful Web APIs and tried the first two chapters. The first chapter of each book is abstract and a summary of the whole book. The beginning of this article is a little simple, starting from teaching you how to enter an address in the address bar to access the web page (someone's girlfriend can't do this ), the second chapter is a simple example. The book consists of three keywords: "Restful" "Web" "APIs". It seems nonsense... but the three words must be added up to be the core of the book. Rest is too generic and restful URI is accurate. I believe the subsequent sections focus on how to design a restful Uri.


2. I also want to talk about rest.

Rest, representational state transfer, literally: declarative state transfer. Why can't I understand it for a while? I don't know at first. How can a normal person understand the meaning of a sentence without a subject or object? completion: the State of the resource changes through interactive presentation data between the browser and the server. It seems that I have translated it again. For example, our server has a book in the status of ID = 1, name = "book1"; well, now let's get it over HTTP, and the server returns id = 1 to us, name = "book1" status. At this time, our browser also becomes status 1. Now I want to change its name to "book2", so let's post it over HTTP. This post has parameters (ID = 1, name = "book2 ") use <form>; in our browser, the book is state 2 at this time. When we post to the server, status 2 is "transferred" to the server. (no matter how the server handles it first) the result server is changed to status 2. This is not the so-called status transfer.

What do you say if you want to express your understanding of rest in one sentence? I would say: restful Uri has no verbs. You may also know that the restful URI for getting a book is "book/1" rather than "getbook/1 ". Because rest calls everything on the server resources, a book is a resource and entity. Then you will ask, where is the action? In HTTP. HTTP has the get method. This is the verb. I will tell you that there are still Delete methods in HTTP, so I have never been familiar with it. This book focuses on five of the HTTP 8 methods, namely get head post put Delete. Also, there is no version of restful URI. To be honest, is there a new or old book, hacker and painter, on my shelf?


3. Restful

Restful. Restful is a design style, not a standard. The standard must be observed, and the style will not be wrong if it is not observed. It just changes. Style, I know what style is when I play ghost weeping, Or is it better to ask Uncle bird? Discretion. I have done a few web projects, all of which are bonded by some functions. Uri is also designed at will. to delete a piece of data, I will use "deletebook? Id = 1 ", which is actually a GET request. I don't know what it is, but it is definitely not restful. People always like to use rest with soap and XML-RPC, said rest is much better than the latter two, the latter two are not very familiar with it. One thing worth noting is that we usually use a certain mode/style during development. Learning this mode/style will give us a better understanding of development. Where do these patterns come from? I would like to refer to the J2EE Core mode, "the mode is summarized ". It also explains why we don't know this pattern, but we are using it at ordinary times, because these pattern styles are also summed up by masters with more experience.

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.