“This is the 14th day of my participation in the November Gwen Challenge. See details of the event: The Last Gwen Challenge 2021”.


Tips: This article is 800 words in total, and it takes about 1-3 minutes to finish reading. I hope this article will be helpful to you. If you have any good suggestions or opinions during reading, please leave a comment or send me a private message at the bottom of this article.


One: Restful API display

Without further ado, let’s show you a Restful API

1,// Add a new article
@RequestMapping(value = "/articles",method = RequestMethod.POST)

2,// Delete an article
@RequestMapping(value = "/articles",method = RequestMethod.DELETE)

3,// Delete an article under an article category
@RequestMapping(value = "/types/{id}/articles",method = RequestMethod.DELETE)

4,// Query an article
@RequestMapping(value = "/articles/{id}",method = RequestMethod.GET)

5,// Query all articles in a category of articles
@RequestMapping(value = "/types/{id}/articles",method = RequestMethod.GET)

6,// Modify an article (all attributes)
@RequestMapping(value = "/articles/{id}",method = RequestMethod.PUT)

7,// Modify an article (some attributes)
@RequestMapping(value = "/articles/{id}",method = RequestMethod.PATCH)
Copy the code

The origin of Restful API style

Representational State Transfer (Rest), which stands for expressive State Transfer, was proposed by Dr. Roy Thomas Fielding in 2000 and represents a new architectural style that is lightweight, cross-platform, and cross-language.

Application Programming Interface (API): Commonly known as an Interface, it is a set of Programming Interface specifications. The client and server communicate data through request response.

RestfulAPI: this is not a new technology, but a style of API design based on Rest architectural ideas.

Benefits of Restful API style

(I) Advantages:

  1. It’s resource-oriented (noun)

  2. You know what you need from the URL

  3. Through the Http Method (get/post…). You know what to do with resources

  4. What do I know from the Http Status Code

(II) Advantages:

(1) Know what resources are needed by URL: API of Restful style can see what resources need to be operated by URL directly, with semantics.

(2)Restful API is resource-oriented (name), that is, there is no corresponding verb in THE URL, the operation for the resource is through Http Method(i.e., post-add, delete-delete, PUT – change (generally provide all information about the entity), patch-change (modify some attributes of the entity), get-search) to implement.

(3) Know the result through Http Status Code: such as the common 200(success), 400(wrong request parameters), 500(server error), etc.

Note 4: Restful API style

  1. Requests for resources should be plural rather than singular because Restful API style is resource-oriented (noun)

  2. Mandatory API version declaration, do not publish no version of the API, such as: APi.v1 /blogs(open and closed principles), to expand development, to modify the closed, if you need to add new functions later, you can directly add the version number of the new interface.

Five:

Whether in an interview or at work, we often hear people ask questions about Restful apis. In fact, it is not as mysterious as we imagine. It is just a setting API architecture style, rather than a new technology.

Believe me, after reading this article, You have been Restful API has a new understanding, if still have what problem need feedback, you can leave a message below or direct messages me, I will see for the first time reply, if you think the words are helpful to you, give me a thumb up trouble and attention, later to share more technical knowledge, finally, thank you for your reading, if you can help to you, that is my biggest harvest.