Rest-style Web Development

Source: Internet
Author: User

Business scenario:

Taking the Web service of a part warehouse as an example to explain the basic idea of rest web service. The parts warehouse deployed on the server releases some external services, so that the customer can:

L obtain a component list.

L obtain detailed information about a specific component.

L submit a purchase list (OP ).

L retrieve component list

 

Implementation:

Rest-based Web services can be accessed through a URI. Therefore, it is very simple to call a web service. The customer needs to obtain a list of parts in the Order1 order. If there is a Web Service partslist to implement this function, you can use http://www.anycorp.com/partslistto get the part rolling. The customer only needs to call it like this. It is transparent to the customer as to how the server is implemented. Because it is transparent to customers, the server can freely modify resources without affecting customers, thus achieving loose coupling.

After the customer knows that the previous URL is used, the server will return a document containing the part list, namely:

<? XML version "1.0">

<P: Parts xmlns: P = "http://www.anycorp.com"

Xmlns: xlink = "http://www.w3.org/5o/xlink”>

<Part id = "00345" xlink: href = "http://www.anycorp.com/partslist/00345">

<Part id = "00346" xlink: href = "http://www.anycorp.com/partslist/00133">

</P: Parts>

The returned document contains links to each part. The customer can select a proper link to migrate the resources that the link points to the customer to achieve self-maintenance of the customer's status. This is a key feature of rest. Obtains detailed information about a specific component.

If you want to return detailed information for each part in XML format, you only need to add the part number parameter after the URL, such as http://www.anycorp.com/partslist/00345. The following document will be returned:

<? XML version = "1.0">

<P: Part xmlns: P = "http://www.parts-depot.com"

Xmlns: xlink = "http://www.w3.org/5o/xlink”>

<Part-ID> 00345 </part-ID>

<Name> widget-A </Name>

<Description> This part is used within the FRAP Assembly </description>

<Specification xlink: href = "http://www.anycorp.com/partslist/00345/specification”"/>

<Unitcost currency = "USD"> 0.10 </unitcost>

<Quantity> 10 </quantity>

</P: Part>

From the data returned above, this data is linked to more data. Customers can continue to select these links to obtain more detailed data, which is the key to rest.

submit a purchase list (OP). This service uses a URL pointing to the PO. The customer creates a po instance document according to the PO format pre-defined in the part warehouse. The customer submits Po. XML as the content carried by http post. The PO service responds to this po submission request, so that the customer can retrieve, update, and edit this po at any time. Po becomes a piece of information shared between the client and the server. The shared information (PO) is accessed by a URL specified by the server and exposed as a web service.

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.