Online grooming for rest and restful API understanding

Source: Internet
Author: User
Tags representational state transfer

First, what is rest?

Rest is not the word "rest", but a few acronyms-representational state Transfer Direct translation: Presentation layer status transfer, but this translation normal people simply do not understand, find a best understanding of the argument is that theURL location resources, Use the HTTP verb (get,post,delete,detc) to describe the operation .

Ii. What are the characteristics of the Restful API interface?

Rest describes a form of interaction between the client and server in the network; Rest itself is impractical, and practical is how to design restful APIs (restful network interfaces).

Root Path of 1.URL
http://API. chesxs.com/v1
2. Need to have API version information
http://api.chesxs.com/v1
Use only nouns to specify resources in 3.URL, without verbs, and recommend plural

In the RESTful API provided by the service (Server), only nouns are used in URLs to specify resources, and verbs are not used in principle. A "resource" is the core of the rest architecture, or the entire network processing. Like what:

Http://api.chesxs.com/v1/cars//Get a list of vehicles under an account http://api.chesxs.com/v1/fences//Get a list of fences under an account
4. Use the verbs in the HTTP protocol to add, modify and delete resources. The use of HTTP verbs to realize the state twist of resources
get is used to get resources, and POST is used to create new resources (or to update resources). For example: POST http://api.chesxs.com/v1/car: Add a vehicle put to update resources, delete to remove resources. For example: DELETE http://api. Chesxs


wrong use : GET http://api.chesxs.com/v1/ Delete vehicle
5.GET should be secure and will not change the state of the resource

This should be very well understood, get is just to get the resources, and not involve adding, updating, deleting resources.

6. Return the status code using the correct HTTP status code

Commonly used are 404,200,500,400 and so on.

Summary, look at a standard RESTful API to be able to do

Look at the URL to know what the resources to operate, is to operate the vehicle or fence to see the HTTP method to know what the action is, whether to add (post) or delete (delete) to see the HTTP Status code to know the results of the operation, Is it a success (200) or an internal error (500)

Online grooming for rest and restful API understanding

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.