In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to unify the api address of the external interface, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.
Common practices are
1. Use if or case statements to determine parameter values; advantages: simple and easy to understand
Disadvantages: too many interfaces, too many if or case branches, ugly code
two。 Dynamic proxy how to parse the parameters, I am not very clear about calling the function.
Does 3.spring implement this kind of functionality?
Can Spring achieve this kind of function?
Why not look at the documents? The categorization is very clear in the Spring MVC documentation. You only need to see the Request Mapping section: https://docs.spring.io/spring/docs/5.2.5.RELEASE/spring-framework-reference/web.html#mvc-ann-requestmapping
API is required to share a URL and call different methods with different parameters, right?
The frontend requests server-side API, and the parameters include the following forms: HTTP Method (GET, POST, PUT, DELETE...) Path Variable (variables in the URL path) Request Parameter (after the question mark, the most common way to pass parameters. This approach can fully meet the current problem.) The parameter Consumable Media Types in Header (whether the request body is JSON or XML) permission (login is not logged in, what is the role after login, access to different interfaces). Strictly speaking, this is not a parameter, but the server side to further determine the role of the user.
Can be thought of as parameters. Only Path Variable may change the URL path, so the other five forms are described below.
1. Same URL, different HTTP Method
It is the URL of / persons, calling the getPerson and add methods, respectively.
2, same URL, different Request Parameter
Both / pets, the URL,/pets?type=cat and / pets?type=dog, call different methods.
3. Different parameters in the same URL,Header
Both / pets, the URL,/pets?type=cat and / pets?type=dog, call different methods.
4, same URL, different Consumable Media Types
It is the URL of / pets. The requested data is in different formats and different methods are called.
5. The same URL has different permissions
Both / persons, the URL,Admin and User, call different methods. Admin can get all the data, and User can only get the data that it has permission.
The above Annotation can be combined freely. Some are also Class-level, but can be annotated on the Controller class.
After reading the above, do you have any further understanding of how the external interface unifies the api address? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.