Disclosure of Invention
Aiming at the reasons that the intensive API and the discrete API management mode have defects in the prior art, the invention provides the following technical scheme.
The invention adopts a technical scheme that:
an application programming interface API management method, comprising:
constructing an API parent class file, wherein the API parent class file can be used for network requests;
carrying out module differentiation classification according to project scenes, and establishing module API files according to the modules;
and receiving a network request demand, matching a corresponding module API file according to a project scene of the network request demand, and opening an interface of the project scene in the corresponding module API file, wherein the interface is used for calling the API parent file to carry out the network request.
Optionally, the constructing the API parent file specifically includes:
writing the public function of the API parent class file, and integrally managing the public function, wherein the public function comprises the following encapsulated functions: the APP requests data from the server, the APP uploads data to the server and the APP downloads data.
Optionally, each module API file stores a network request interface of the module, and can call a public function of the API parent file to make a network request.
Optionally, the interface is configured to call the API parent file to perform a network request specifically includes:
the interface is used for calling the public function of the API parent file to carry out network request.
Optionally, the module differentiation classification is performed according to project scenes, and the module API file establishment according to the modules specifically includes:
and carrying out module differentiation classification on the service modules according to project scenes, and classifying the service modules into different subclasses according to the project, wherein the module API files comprise different subclasses.
Optionally, the disclosed functionality is performed in a parent high-level language application programming interface.
The invention adopts another technical scheme that: an application programming interface API requesting method, comprising:
initiating a network request;
matching corresponding module API files according to the project scene of the network request, and calling interfaces of the project scene in the corresponding module API files, wherein the interfaces are used for calling API parent class files to perform the network request;
and receiving target data returned based on the network request, and returning the target data to the application program.
The invention adopts another technical scheme that: an application programming interface API management device comprising:
the construction module is used for constructing an API parent class file which can be used for network requests;
the classification and establishment module is used for carrying out module differentiation classification according to project scenes and establishing module API files according to the modules;
the receiving and opening module is used for receiving network request demands, matching corresponding module API files according to project scenes of the network request demands, opening interfaces of the project scenes in the corresponding module API files, and calling the API parent class files to carry out network requests.
The invention adopts another technical scheme that: an API management device for an application programming interface,
comprising the following steps:
a memory for storing a computer program;
and the processor is used for realizing the steps of the application programming interface API management method when executing the computer program.
The invention adopts another technical scheme that: a computer readable storage medium having stored therein program data for implementing a method as described above when executed by a processor.
The beneficial effects of the invention are as follows: different from the prior art, the Application Programming Interface (API) management method provided by the invention comprises the steps of constructing an API parent file, wherein the API parent file can be used for network requests; carrying out module differentiation classification according to project scenes, and establishing module API files according to the modules; and receiving a network request demand, matching a corresponding module API file according to a project scene of the network request demand, and opening an interface of the project scene in the corresponding module API file, wherein the interface is used for calling the API parent file to carry out the network request. According to the method, module differentiation and classification are carried out according to project scenes, module API files are established according to the modules, namely, the modules are disassembled according to the project scenes, all APIs are not gathered together, and the coupling degree is low. For classification reasons, the total amount of traffic effectuators required to write by the network layer is reduced, reducing the effort as a whole. In addition, the parent class is set to close when requesting, namely, network requests are not carried out on all subclasses, and the network request method is put into the parent class to be executed, so that customization of a classification level is realized, customization is enhanced generally, and the aggregation degree is higher.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. It is to be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention. It should be further noted that, for convenience of description, only some, but not all methods and processes related to the present invention are shown in the accompanying drawings. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
The terms "comprising" and "having" and any variations thereof herein are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed steps or elements but may include other steps or elements not listed or inherent to such process, method, article, or apparatus.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the invention. The appearances of such phrases in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
In software engineering, high cohesive and low coupling are criteria for judging whether a code is designed well or not, and particularly when an object-oriented program is designed, whether cohesive property of a class is high or not and whether coupling degree is low or not are judged. The purpose is to greatly enhance the reusability and portability of the module. Generally, the higher the degree of cohesion of the modules in the program structure, the lower the degree of coupling between the modules. Cohesion is the functional measure of the links within a module, and a good cohesive module should do exactly one thing. Coupling is a measure of the interconnection between modules in a software architecture, and the strength of coupling depends on the complexity of the interfaces between the modules, the point of entry or access to a module, and the data passing through the interface.
Besides high cohesion and low coupling, in software engineering, there is a concept of a parent class, that is, two classes (files) are relationships between a parent and a child, and the child may inherit functions (disclosure methods) of the parent class, for example, in the embodiment of the present invention, the parent class may be an apimode, and the child class may be AApis, BApis, CApis., that is, the AApis, BApis, CApis file has functions of the apimode (that is, the child class AApis, BApis, CApis and other subclasses may call the disclosure methods of the apimode of the parent class to implement the disclosure functions), so that the apimode may write a closing-in of functions required by some subclasses, that is, the parent class encapsulates basic functions.
The method combines the existing main stream API management mode in the current market, has the advantages of being high in strength and short in length, decoupling (decomposing into AApis, BApis, CApis and other subclasses) is carried out through service classification and father-son class design, and a mode of closing up (AApis, BApis, CApis and other subclasses realize the function method disclosed by father class APIMananager) is requested to be carried out on a network to realize high strength, so that the structure of high strength and low coupling of the API codes is realized.
As shown in fig. 1, an embodiment of the present invention provides an API management method, including:
step 10, constructing an API parent class file, wherein the API parent class file can be used for network requests;
step 20, carrying out module differentiation classification according to project scenes, and establishing module API files according to the modules;
step 30, receiving a network request demand, matching a corresponding module API file according to a project scene of the network request demand, and opening an interface of the project scene in the corresponding module API file, wherein the interface is used for calling the API parent file to perform the network request.
The beneficial effects of the invention are as follows: different from the prior art, the Application Programming Interface (API) management method provided by the invention comprises the steps of constructing an API parent file, wherein the API parent file can be used for network requests; carrying out module differentiation classification according to project scenes, and establishing module API files according to the modules; and receiving a network request demand, matching a corresponding module API file according to a project scene of the network request demand, and opening an interface of the project scene in the corresponding module API file, wherein the interface is used for calling the API parent file to carry out the network request. According to the method, module differentiation and classification are carried out according to project scenes, module API files are established according to the modules, namely, the modules are disassembled according to the project scenes, all APIs are not gathered together, and the coupling degree is low. For classification reasons, the total amount of traffic effectuators required to write by the network layer is reduced, reducing the effort as a whole. In addition, the parent class is set to close when requesting, namely, network requests are not carried out on all subclasses, and the network request method is put into the parent class to be executed, so that customization of a classification level is realized, customization is enhanced generally, and the aggregation degree is higher.
Further, the construction of the API parent file specifically includes:
writing the public function of the API parent class file, and integrally managing the public function, wherein the public function comprises the following encapsulated functions: the APP requests data from the server, the APP uploads data to the server and the APP downloads data.
Specifically, firstly, writing a public function (AApis, BApis, CApis and other functions commonly required by subclasses) on an API parent file (APIManager), integrating a series of public functions, such as public function packages of pulling data (APP requests data from a server), reporting data (APP uploads data to the server), APP downloading and the like, and not relating to specific business logic;
further, each module API file stores the network request interface of the module, and can call the public function of the API parent file to carry out network request.
Further, the module differentiation classification is performed according to the project scene, and the module API file establishment according to the module specifically comprises:
and carrying out module differentiation classification on the service modules according to project scenes, and classifying the service modules into different subclasses according to the project, wherein the module API files comprise different subclasses.
Specifically, the module differentiation classification is carried out on the projects, and according to different project scenes, each module establishes an API management class (AApis, BApis, CApis..) which is a module API file, each API management class only stores the network request interface of the module, and only calls the method provided by the father class to carry out network request, and does not process specific request logic and data logic.
Further, the interface is configured to call the API parent file to perform a network request specifically includes:
the interface is used for calling the public function of the API parent file to carry out network request.
In the specific business code writing process, when the project scene of the network request is involved, the API writing is directly carried out in the corresponding module API management class (namely the corresponding module API file, such as BApis)
For example: the pulling of order data is needed in the B module, and a network request is needed, and at the moment, an interface- (void) getOrderDataFromServer for pulling the order data is needed to be opened in BApis class;
the specific implementation of the interface is to call a method in the parent class apimanagement to make a network request.
The key point of the invention is that the service modules of different project scenes are disassembled by API, module API files are built according to the modules, namely, the service according to the project is divided into AApis, BApis, CApis and other subclasses, and all APIs are not gathered together, namely, low coupling is realized;
in addition, the API parent file is set to close when the request is made, namely, network requests are not made in all subclasses, and a public function (public function) method is put into a parent high-level language application programming interface (HLLApi manager) to be executed so as to achieve high cohesion;
in the specific service code writing process, the subclasses AApis, BApis, CApis and the like of the service codes requiring the network do not relate to specific network request logic, and the network request codes of the parent class HLLApi manager do not relate to specific service logic;
when developing different service modules, the specific request mode of the API parent file is not needed, only the interface of the API parent file is required to be called for network request, the module API file is only managed by the API interface and is not required to be specifically requested by the network, the classification of the APIs is carried out according to the module, and the APIs of the module are not required to be provided with Manager files, and are placed in a subclass, so that intensive placement in the same class can be avoided, a large number of class files are not needed to be generated like discrete, the service logic and the technical logic with clear high-cohesion low-coupling design mode in software engineering are met, and the defects of the intensive API management mode and the discrete API management mode in the prior art are overcome.
The embodiment of the invention mainly solves the pain point of the API management mode existing in the prior art in the development of the iOS app, optimizes the experience of a developer by optimizing the code structure, thereby improving the development efficiency and the robustness of the code, and ensuring that the code has more expansibility and a code logic structure is clearer.
As shown in fig. 2, the embodiment of the present invention further provides an API requesting method, including:
step 60, initiating a network request;
step 70, matching corresponding module API files according to the project scene of the network request, and calling interfaces of the project scene in the corresponding module API files, wherein the interfaces are used for calling API parent class files to perform the network request;
and step 80, receiving target data returned based on the network request, and returning the target data to the application program.
It should be noted that, the API request method is a method implemented by the API management method according to the above embodiment, and the process of initiating a network request and returning template data to the network demand initiator is implemented together. The application programming interface API request method of the present embodiment and the application programming interface API management method of the foregoing embodiments are based on the same inventive concept, and specific implementation processes of the application programming interface API request method are detailed in the method embodiment, and technical features of the foregoing embodiments are correspondingly applicable in the present embodiment, and are not described in detail herein.
According to the above-described embodiment, as shown in fig. 3, the embodiment of the present invention further provides an application programming interface API management device 50, the application programming interface API management device 100 including:
a building module 51, configured to build an API parent file, where the API parent file may be used for a network request;
the classifying and establishing module 52 is configured to perform module differentiation classification according to project scenes, and establish module API files according to modules;
the receiving and opening module 53 is configured to receive a network request requirement, match a corresponding module API file according to a project scene of the network request requirement, and open an interface of the project scene in the corresponding module API file, where the interface is configured to call the API parent file to perform a network request.
The application programming interface API management device of the present embodiment and the application programming interface API management method of the foregoing embodiments are based on the same inventive concept, and specific implementation processes thereof are detailed in the method embodiment, and technical features of the foregoing application programming interface API management method embodiment are correspondingly applicable in the present embodiment, and are not described in detail herein.
As shown in fig. 4, the embodiment of the present invention also provides an application programming interface API management device 100.
The application programming interface API management device 100 includes a processor 110 and a memory 120. Wherein the processor 110 and the memory 120 are coupled. The memory 120 stores therein a computer program for executing the above-described API management method.
The application programming interface API management device 100 includes:
a memory 120 for storing a computer program;
a processor 110 for implementing the steps of the application programming interface API management method as described above when executing the computer program.
The application programming interface API management apparatus of the present embodiment and the application programming interface API management method of the foregoing embodiments are based on the same inventive concept, and specific implementation processes thereof are detailed in the method embodiment, and technical features of the foregoing application programming interface API management method embodiment are correspondingly applicable in the present embodiment, and are not described in detail herein.
Referring specifically to fig. 5, fig. 5 is a schematic structural diagram of an embodiment of a computer readable storage medium according to the present invention.
Included in computer readable storage medium 200 is program data 210. The program data 210, when executed by a processor, may implement the application programming interface API management methods described above.
Unlike the prior art, the present invention provides an application programming interface API management method.
The beneficial effects of the invention are as follows: different from the prior art, the invention provides an Application Programming Interface (API) management method, which comprises the steps of constructing an API parent file, wherein the API parent file can be used for network requests; carrying out module differentiation classification according to project scenes, and establishing module API files according to the modules; and receiving a network request demand, matching a corresponding module API file according to a project scene of the network request demand, and opening an interface of the project scene in the corresponding module API file, wherein the interface is used for calling the API parent file to carry out the network request. According to the method, module differentiation and classification are carried out according to project scenes, module API files are established according to the modules, namely, the modules are disassembled according to the project scenes, all APIs are not gathered together, and the coupling degree is low. For classification reasons, the total amount of traffic effectuators required to write by the network layer is reduced, reducing the effort as a whole. In addition, the parent class is set to close when requesting, namely, network requests are not carried out on all subclasses, and the network request method is put into the parent class to be executed, so that customization of a classification level is realized, customization is enhanced generally, and the aggregation degree is higher.
The foregoing description is only illustrative of the present invention and is not intended to limit the scope of the invention, and all equivalent structures or equivalent processes or direct or indirect application in other related technical fields are included in the scope of the present invention.