Introduction to REST #Reprinted #

Source: Internet
Author: User
Tags representational state transfer

From http://www.cnblogs.com/shanyou/archive/2012/05/12/2496959.html

Dudu's HttpClient + ASP. NET Web API, another choice discussed outside of WCF, shows that the restful API is also beginning to get a lot of attention in the. The concept of REST (representational state Transfer) has been proposed for more than 10 years, and has become the mainstream of today's design open API. Maybe everyone is handy. NET System consolidation uses WCF (and even web Service) for cross-host communication, but Microsoft also started to promote the rest architecture's ASP. If you do not know RESTful first, then the content is really a bit hard, like a professional noun, for example, you can see in the ASP. NET Web API file a large number of Resource (resources) This word, URI I can understand, and Resource what is the relationship?

There are a lot of articles about rest and restful concepts, and here are some of the references I think are good:

    • Definition of Wikipedia: REST
    • What is rest and restful? The rest theory is detailed in Chinese, where you can learn that WCF restful is an RPC-style Web service, and the ASP. NET Web API belongs to a RESTful Web service.
    • In the text of the rest Infoq, there is even a link to the Chinese translation of Roy T. Fielding's rest doctoral dissertation. It's also worth mentioning that you may not have heard of Roy Fielding, but if you know that he is the main author of the HTTP specification and one of the initiators of the Apache HTTP Server project, there should be no doubt about his weight in the Web technology world.

The above article suggests a serious reading, here we briefly introduce the rest as a primer, understand the rest can make us on the path of the ASP Web API smoother.

What is rest?

REST (representational state Transfer), Transfer is "status transfer" or "state transfer", representational Chinese is translated as "characterization", "figurative", together it is "representational state transfer "or" representational state transfer "or" representational state transfer ", however, a general article or technical document will not be written in the translated Chinese, but rather directly refer to rest or restful to represent, because rest a whole concept, want to use only six Chinese words to complete express really difficult.

The term REST is based on the architectural styles and the Design of network-based software architectures, and we'll start with a simple title, which should be an architectural style ( Architectural Styles) and software architecture (software architectures), and based on the network (network-based), focus on:

    • Schema style (architectural styles)
    • Software architecture (software architectures)
    • Network (network-based)-based

REST itself is a design style rather than a standard. REST talks about a very important thing, how to use Web standards correctly, such as HTTP and URIs. The best way to learn about REST is to think about and understand the Web and how it works . If you design an application that conforms to the rest principles, these restful rest services can be referred to as "RESTful Web service" or "restful web api ". The end of "-ful" emphasizes that their design fits perfectly with the recommendations in the REST paper.

Resource RESOURCE

in the REST the resources in (Resource) represents a resource on the entire network. a wide variety of resources are available on the network, and resources on the network are provided by URIs (Uniform Resource identifiers, Uniform Resource Identifier). In retrospect, how do you connect to my blog, you may directly enter www.cnblogs.com/shanyou this domain through the browser to reach the homepage, also can use the bookmark or the link on the network, by click later connected to my blog. Then, you want to read this article titled "rest Introduction", so you can click on the title link of this article, then read it. Let's take a quick look at the whole process:

    1. Client sends a request to Http://www.cnblogs.com/shanyou via URL (http://www.cnblogs.com/shanyou)
    2. Www.cnblogs.com/shanyou receives the request, responds to the homepage to the Client
    3. The Client then clicks on the REST article link (assuming http://www.cnblogs.com/shanyou/archive/2011/06/30/2095018.html) to http://www.cnblogs.com/ Shanyou issued a request to archive/2011/06/30/2095018.html this article
    4. Www.cnblogs.com/shanyou receives the request, responds to the REST article content to the Client

A specific symbol of the Client's access to resources through URIs (representational). The Client obtains these specific symbols to enable these applications to transform their state (in the browser, get HTML, CSS, JavaScript ...). To generate the interface), with constant access to the specific symbol of resources, the client side constantly changing its state, so the constant repeated (iterations) process is called representational State Transfer.

Using WEB standards

The

Above is the closest to everyday paradigm, which is called get in the HTTP specification, that is, by URL to get the resources I want. Another common example is to fill out a form, for example, a login form, I want to log in, you must first send an account and password to a resource, this resource will verify that the data you sent is correct, and then follow up the action. The behavior we send information to a resource is called POST in the HTTP specification. In http/1.1 RFC 2616, section 5.1.1 method, defines eight classes of HTTP methods, in addition to our usual GET and POST, there are PUT and DELETE commonly used in REST. This get, POST, PUT, delete exactly can correspond to our CRUD (Create, Read, Update, DELETE) Four kinds of data operations.

HTTP Method corresponds to curd data processing operation

HTTP Method

Data processing

Description

POST

Create

Add a resource with no ID

GET

Read

Get a resource

PUT

Update

Update a resource. Or add a resource with ID (if the ID does not exist)

DELETE

Delete

Delete a resource

RESTFUL WEB SERVICE

A RESTful Web service (also known as the RESTful web API) is an HTTP-compliant web services that is consistent with the REST principle. We know that a GET request can be delivered via a URL, and the form is specified method= "get| POST "to send a request. But what do we do with a PUT or DELETE request? By RESTful We can define resources in simple URIs and use them in conjunction with HTTP methods.

Resource corresponds to HTTP method

Resources

Resource Description

GET

PUT

POST

DELETE

http://www.cnblogs.com/products/< /p>

Products Yes a set of resource sets

list details for each resource in the group resource collection

Update Current entire set of resources

New or attach a new resource. The action returns the URL of the new resource

Delete entire group of resources

http://www.cnblogs.com/products/1< /p>

Products/1 Yes individual resources

obtain specified resource details

strong> Update or new specified resource

new or append a new element

Delete specified element /p>

The above table is not very like we generally in the order of operation of the database table, into a table data first page (usually a list), this page will have "new, update, delete, detailed" and other links, you want to do what to do, click on that one link. In the RESTful each resource has its own independent URI, the Client enters from a collection of resources or a single resource, whether it is a resource collection or a single resource, we can work with the HTTP method, for example, GET download, PUT update, POST new, delete delete.

The ASP. NET Web API is a framework (framework) that allows you to set up an http Service (HTTP services)on top of framwork. The ASP. NET Web API is the ideal platform for building RESTful applications on the. NET Framework.

In Julie Lerman's how-I see Web API article, a graph is used to concisely illustrate the Web API:

Introduction to REST #Reprinted #

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.