Method, apparatus and computer program product for providing interface
By automatically generating front-end interface specifications for different clients, the problems of large workload and complex maintenance in the existing technology are solved, efficient interface development and maintenance are achieved, and manpower and time costs are saved.
Patent Information
- Application Number
- CN202311276897.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-28
- Publication Date
- 2025-03-28
AI Technical Summary
The prior art is difficult to efficiently provide corresponding API interfaces for multiple clients, resulting in large workloads in interface development, complex maintenance, and difficult to reuse general interface specifications and mapping description documents.
By obtaining predetermined common interface specifications and mapping description documents for different clients, different front-end interface specifications corresponding to various types of clients are automatically generated, thereby providing different front-end interfaces for different clients based on the same set of back-end interfaces.
It minimizes the workload of interface development, easily reuses general interface specifications and mapping description documents, simplifies interface maintenance, and saves labor and time costs.
Smart Images

Figure CN119718301A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer application development, and more particularly, to a method, apparatus, and computer program product for providing an interface. Background Art
[0002] An application programming interface (API) is a set of tools that implement how different software components communicate and interact with each other. API allows different applications to share data and functions so that they can work together effectively. API can be seen as a bridge between multiple applications, which defines how to request or send data, perform operations, and obtain the required response.
[0003] API specifications are a set of rules about how to design, build, and use APIs. These specifications are designed to ensure that APIs can communicate and interact effectively between different applications, while providing a standard way to access and use API functionality. API specifications typically include API endpoints and paths, methods to use when interacting with API endpoints (e.g., GET, POST, PUT, DELETE, etc.), data formats for API requests and responses, and parameter types and formats, etc. When multiple clients have different requirements for the same application, how to efficiently provide corresponding API interfaces for each client is a problem that needs to be solved. Summary of the invention
[0004] The embodiments of the present disclosure propose a method, device and computer program product for providing an interface. In the scheme provided by the embodiments of the present disclosure, a predetermined general interface specification can be obtained, and the general interface specification is associated with the API interface actually provided by the back end. Then, the scheme can obtain a mapping description document for the first client, which describes the conversion relationship between the general interface specification and the first front-end interface specification for the first client. Then, the scheme can generate the first front-end interface specification based on the mapping description document and the general interface specification for the first client. When receiving a request from the first client that conforms to the first front-end interface specification, the scheme can convert the request into a back-end request that conforms to the back-end interface that can be processed by the back-end server based on the first front-end interface specification. In addition, the scheme can also obtain a mapping description document for the second client, which describes the conversion relationship between the general interface specification and the second front-end interface specification for the second client. Then, the scheme can generate the second front-end interface specification based on the mapping description document and the general interface specification for the second client. When receiving a request from the second client that conforms to the second front-end interface specification, the scheme can convert the request into a back-end request that conforms to the same back-end interface that can be processed by the back-end server based on the second front-end interface specification. In this way, the interface developer does not need to develop two sets of interfaces for the first client and the second client with different requirements. Instead, they only need to provide a mapping description document that meets specific requirements to automatically generate different front-end interface specifications corresponding to various types of clients, thereby providing different front-end interfaces for clients with different requirements based on the same set of back-end interfaces. This can minimize the workload for developing interfaces, and at the same time, it can easily reuse common interface specifications and mapping description documents, making interface maintenance easier, thereby saving manpower and time costs.
[0005] In a first aspect of the present disclosure, a method for providing an interface is provided. The method includes obtaining a general interface specification associated with a back-end interface. The method also includes generating a first front-end interface specification based on the general interface specification and a first mapping, the first mapping indicating a conversion relationship between the general interface specification and the first front-end interface specification. The method also includes converting a first front-end request into a first back-end request associated with the back-end interface based on the first front-end interface specification. The method also includes generating a second front-end interface specification based on the general interface specification and a second mapping, the second mapping indicating a relationship between the general interface specification and the second front-end interface specification, the first front-end interface specification being different from the second front-end interface specification. In addition, the method also includes converting a second front-end request into a second back-end request associated with the back-end interface based on the second front-end interface specification.
[0006] In a second aspect of the present disclosure, an electronic device is provided. The electronic device includes one or more processors; and a memory coupled to at least one processor and having instructions stored thereon, which, when executed by at least one processor, causes the electronic device to perform an action, the action including obtaining a general interface specification associated with a back-end interface. The action also includes generating a first front-end interface specification based on the general interface specification and a first mapping, the first mapping indicating a conversion relationship between the general interface specification and the first front-end interface specification. The action also includes converting a first front-end request into a first back-end request associated with the back-end interface based on the first front-end interface specification. The action also includes generating a second front-end interface specification based on the general interface specification and a second mapping, the second mapping indicating a relationship between the general interface specification and the second front-end interface specification, the first front-end interface specification being different from the second front-end interface specification. In addition, the action also includes converting a second front-end request into a second back-end request associated with the back-end interface based on the second front-end interface specification.
[0007] In a third aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, a method for providing an interface is implemented. The method includes obtaining a general interface specification associated with a back-end interface. The method also includes generating a first front-end interface specification based on the general interface specification and a first mapping, and the first mapping indicates a conversion relationship between the general interface specification and the first front-end interface specification. The method also includes converting a first front-end request into a first back-end request associated with the back-end interface based on the first front-end interface specification. The method also includes generating a second front-end interface specification based on the general interface specification and a second mapping, and the second mapping indicates a relationship between the general interface specification and the second front-end interface specification, and the first front-end interface specification is different from the second front-end interface specification. In addition, the method also includes converting a second front-end request into a second back-end request associated with the back-end interface based on the second front-end interface specification.
[0008] It should be understood that the contents described in the summary of the invention are not intended to limit the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:
[0010] Figure 1 A schematic diagram illustrating an example environment in which various embodiments of the present disclosure may be implemented;
[0011] Figure 2A flowchart of a method for providing an interface according to some embodiments of the present disclosure is shown;
[0012] Figure 3 A schematic diagram showing an example of a mapping description document according to some embodiments of the present disclosure;
[0013] Figure 4 A schematic diagram showing an example process of generating a front-end interface specification for a front-end interface according to some embodiments of the present disclosure;
[0014] FIG. 5A to FIG. 5C A schematic diagram showing an example general interface specification, an example mapping description document, and an example mapping function configuration document for generating a new front-end interface specification based on a general interface specification using a mapping description document according to some embodiments of the present disclosure;
[0015] Figure 6 A schematic diagram showing an example process of responding to a request from a client using a generated interface specification document and a mapping function configuration document for a front-end interface according to some embodiments of the present disclosure; and
[0016] Figure 7 A block diagram of a device in which various embodiments of the present disclosure may be implemented is shown. DETAILED DESCRIPTION
[0017] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0018] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit implementations may also be included below.
[0019] An application programming (API) interface (also referred to herein as an interface) is a programming interface used to enable an application client to communicate with an application server. Typically, an application only provides one set of API interfaces for use by each client. However, in some cases, multiple sets of API interfaces need to be provided for multiple types of clients for the same application. For example, in some cases, an application needs to expose multiple sets of different API interfaces for internal and external clients; in some cases, for backward compatibility, there are multiple sets of different versions of API interfaces for the same application; in some cases, different types of clients (e.g., mobile clients and desktop clients) require multiple sets of different API interfaces.
[0020] In some traditional solutions, in order to meet the special needs of the front-end client, a separate set of API interfaces needs to be provided for the client. For example, the back-end can provide a first back-end service and a second back-end service. For the first back-end service, the back-end developer can develop a first set of API interfaces for the first client and a second set of API interfaces for the second client. For the second back-end service, the back-end developer can develop a third set of API interfaces for the first client and a fourth set of API interfaces for the second client. In addition, when two clients have different customization requirements for the same back-end service, two different sets of API interfaces need to be provided for the same function. At this time, the back-end developer needs to develop additional functions to handle different API interfaces. This method takes a lot of effort to implement multiple sets of API interfaces in each back-end service, and there may be repeated code logic in the back-end service, making it difficult to maintain the code. In addition, code specific to a certain client may be added to the business logic code, so the code logic will become more and more complicated over time, which may cause logical errors.
[0021] To this end, an embodiment of the present disclosure proposes a scheme for providing an interface, which can obtain a predetermined general interface specification, and the general interface specification is associated with an API interface actually provided by the back end. Then, the scheme can obtain a mapping description document for the first client, which describes the conversion relationship between the general interface specification and the first front-end interface specification for the first client. Then, the scheme can generate the first front-end interface specification based on the mapping description document and the general interface specification for the first client. When receiving a request from the first client that conforms to the first front-end interface specification, the scheme can convert the request into a back-end request that conforms to the back-end interface that can be processed by the back-end server based on the first front-end interface specification. In addition, the scheme can also obtain a mapping description document for the second client, which describes the conversion relationship between the general interface specification and the second front-end interface specification for the second client. Then, the scheme can generate the second front-end interface specification based on the mapping description document and the general interface specification for the second client. When receiving a request from the second client that conforms to the second front-end interface specification, the scheme can convert the request into a back-end request that conforms to the same back-end interface that can be processed by the back-end server based on the second front-end interface specification. In this way, the interface developer does not need to develop two sets of interfaces for the first client and the second client with different requirements. Instead, they only need to provide a mapping description document that meets specific requirements to automatically generate different front-end interface specifications corresponding to various types of clients, thereby providing different front-end interfaces for clients with different requirements based on the same set of back-end interfaces. This can minimize the workload for developing interfaces, and at the same time, it can easily reuse common interface specifications and mapping description documents, making interface maintenance easier, thereby saving manpower and time costs.
[0022] Figure 1 1 is a schematic diagram of an example environment 100 in which various embodiments of the present disclosure may be implemented. Figure 1 As shown, the environment 100 includes backend services 102 and 104, and provides a set of backend interfaces 106 for requesting the backend services 102 and 104. The environment 100 also includes clients 108 and 110, which can interact with the backend services 102 and 104 to implement various functions. In the environment 100, different interfaces need to be provided for the clients 108 and 110. For example, the clients 108 and 110 may belong to different categories of clients, and the server provides different subsets of the backend interfaces 106 according to the categories of the clients, or for the same backend services 102 or 104, the server needs to provide the clients 108 and 110 with response results in different formats.
[0023] like Figure 1As shown, the environment 100 includes a general interface adapter 112, which can implement general functions related to calling an API interface and can provide a general interface specification 114. The general interface specification 114 is associated with the backend interface 106. For example, the general interface specification 114 can provide a definition of the backend interface 106, which can include the endpoints of the backend interface 106, declarations of elements and attributes, definitions of data types, request formats, response formats, parameters and other information. In the embodiments of this article, the Representational State Transfer (REST) API and the corresponding Open Application Programming Interface (OpenAPI) specification are used as examples, but the solutions provided in the embodiments of this article can also be used for other API interfaces and other specifications. The environment 100 also includes a mapping description document 116 for the client 108. The mapping description document 116 can describe the conversion relationship between the general interface specification 114 and the front-end interface specification 126 for the client 108. As shown in FIG. Figure 1 As shown, the mapping description document 116 includes mapping operations 118-1, 118-2, ..., 118-N (collectively referred to as mapping operations 118 herein), and the mapping operations in the mapping operations 118 are arranged in sequence. The environment 100 also includes a mapping function configuration document 120 for the client 108, in which mapping functions 122-1, 122-2, ..., 122-N (collectively referred to as mapping functions 122 herein) can be implemented, and the mapping function 122 can be referenced in the mapping operations 118 of the mapping description document 116 to implement various mapping functions. The environment 100 also includes a converter 124, which can use the mapping description document 116 to convert the general interface specification 114 into a front-end interface specification 126 for the client 108.
[0024] like Figure 1 As shown, the client 108 can initiate a front-end request 130 by calling the front-end interface defined by the front-end interface specification 126. The environment 100 includes a dedicated interface adapter 128 of 108, and the dedicated interface adapter 128 can use the front-end interface specification 126 and the mapping function configuration document 120 to convert the front-end request 130 into a back-end request 132 for calling the back-end interface 106. The back-end request 132 can request the back-end service 102 or 104. In this way, the back-end server can provide response information corresponding to the back-end service 102 or 104 based on the received back-end request 132.
[0025] like Figure 1 As shown, the environment 100 also includes a mapping description document 136 for the client 110, and the mapping description document 136 can describe the conversion relationship between the general interface specification 114 and the front-end interface specification 146 for the client 110. Figure 1As shown, the mapping description document 136 includes mapping operations 138-1, 138-2, ..., 138-N (collectively referred to as mapping operations 138 herein), and the mapping operations in the mapping operations 138 are arranged in sequence. The environment 100 also includes a mapping function configuration document 140 for the client 110, in which mapping functions 142-1, 142-2, ..., 142-N (collectively referred to as mapping functions 142 herein) can be implemented, and the mapping function 142 can be referenced in the mapping operations 138 of the mapping description document 136 to implement various mapping functions. The environment 100 also includes a converter 144, which can use the mapping description document 116 to convert the general interface specification 114 into a front-end interface specification 146 for the client 110.
[0026] like Figure 1 As shown, the client 110 can initiate a front-end request 150 by calling the front-end interface defined by the front-end interface specification 146. The environment 100 includes a dedicated interface adapter 148 for the client 110. The dedicated interface adapter 148 can use the front-end interface specification 146 and the mapping function configuration document 140 to convert the front-end request 150 into a back-end request 152 for calling the back-end interface 106. The back-end request 152 can request the back-end service 102 or 104. In this way, the back-end server can provide response information corresponding to the back-end service 102 or 104 based on the received back-end request 152.
[0027] It should be noted that Figure 1 In the illustrated environment 100, the converters 124 and 144 are shown as two separate components, but they may also be implemented as the same component. It should also be noted that the mapping function configuration documents 120 and 140 are optional, and when the conversion from the general interface specification 114 to the front-end interface specification 126 is not very complex, the mapping operation 118 in the mapping description document 116 may not reference the mapping function 122 that can perform complex operations, and thus the mapping function configuration document 120 may be omitted. Similarly, when the conversion from the general interface specification 114 to the front-end interface specification 146 is not very complex, the mapping function configuration document 140 may also be omitted.
[0028] In this way, only one group of back-end interfaces 106 can be developed, and multiple mapping description documents for multiple clients are provided (and corresponding multiple mapping function configuration documents are optionally provided), and the front-end interface specification specific to the client can be generated, so that a specific group of front-end interfaces can be provided to the client to realize the specific needs of the client. This method can save the time and labor cost of developing interfaces, reduce the complexity of interface implementation, and improve the maintainability of interfaces. In addition, since the mapping description document and the mapping function configuration document are reused for multiple clients of the same category, and the front-end interface specification specific to each client is generated, time and labor cost can be further saved.
[0029] Figure 2 FIG. 2 is a flow chart of a method 200 for providing an interface according to some embodiments of the present disclosure. Figure 2 As shown, at block 202, method 200 may obtain a general interface specification associated with a backend interface. Figure 1 In the environment 100 shown, a general interface specification 114 associated with the backend interface 106 may be obtained. For example, the general interface specification 114 may provide a definition for the backend interface 106, which may include information such as endpoints, element and attribute declarations, data type definitions, request formats, response formats, parameters, etc. of the backend interface 106.
[0030] At block 204, method 200 may generate a first front-end interface specification based on the general interface specification and the first mapping, where the first mapping indicates a conversion relationship between the general interface specification and the first front-end interface specification. Figure 1 In the illustrated environment 100, the converter 124 can generate a front-end interface specification 126 for the client 108 based on the general interface specification 114 and the mapping description document 116. For example, the converter 124 can sequentially apply one or more mapping operations 118 specified in the mapping description document 116 to the general interface specification 114, thereby generating a front-end interface specification 126 for the client 108.
[0031] At block 206, method 200 may convert the first front-end request into a first back-end request associated with the back-end interface based on the first front-end interface specification. Figure 1In the illustrated environment 100, the dedicated interface adapter 128 receives a front-end request 130 from the client 108, and the interface called by the front-end request 130 is a front-end interface specific to the client 108 and conforms to the definition in the front-end interface specification 126. The dedicated interface adapter 128 can convert the front-end request 130 into a back-end request 132 based on the front-end interface specification 126, and the back-end request 132 calls the back-end interface 106 that can be processed by the back-end server, so that the back-end server can respond to the back-end request 132 and provide the back-end service 102 or 104 for the client 108.
[0032] At block 208, method 200 may generate a second front-end interface specification based on the general interface specification and the second mapping, the second mapping indicating a relationship between the general interface specification and the second front-end interface specification, the first front-end interface specification being different from the second front-end interface specification. Figure 1 In the environment 100 shown, the converter 144 can generate a front-end interface specification 146 for the client 110 based on the general interface specification 114 and the mapping description document 136. For example, the converter 144 can sequentially apply one or more mapping operations 138 specified in the mapping description document 136 to the general interface specification 114, thereby generating a front-end interface specification 146 for the client 110. Since the client 108 and the client 110 may have different requirements for the back-end service (for example, for the same back-end service, the formats of the request parameters sent by the client 108 and the client 110 are different or the formats of the received response results are different, or the client 108 has the right to use the back-end service 102 but the client 110 does not have the right to use the back-end service 102, etc.), and two different sets of interfaces need to be provided for them, the front-end interface specification 126 and the front-end interface specification 146 may be interface specifications that define different front-end interfaces.
[0033] At block 210, method 200 may convert the second front-end request into a second back-end request associated with the back-end interface based on the second front-end interface specification. Figure 1 In the illustrated environment 100, the dedicated interface adapter 148 receives a front-end request 150 from the client 110, and the interface called by the front-end request 130 is a front-end interface specific to the client 110 and conforms to the definition in the front-end interface specification 146. The dedicated interface adapter 148 can convert the front-end request 150 into a back-end request 152 based on the front-end interface specification 146, and the back-end request 152 calls the back-end interface 106 that can be processed by the back-end server, so that the back-end server can respond to the back-end request 152 and provide the back-end service 102 or 104 for the client 110.
[0034] In this way, the interface developer does not need to develop two groups of interfaces for the client 108 and the client 110 with different requirements, but only needs to provide mapping description documents 116 and 136 that meet specific requirements, and the front-end interface specification 126 for the client 108 and the front-end interface specification 146 for the client 110 can be automatically generated, thereby providing different front-end interfaces for clients with different requirements based on the same group of back-end interfaces. This can minimize the workload for developing interfaces, and can easily reuse common interface specifications and mapping description documents, making interface maintenance simpler, improving development and maintenance efficiency, and thus saving manpower and time costs.
[0035] As mentioned above, one or more mapping operations are included in the mapping description document. In some embodiments, the mapping operation includes the mapping operation indicator of the type of the mapping operation and the path of the position of the target object being operated. In some embodiments, the type of the mapping operation includes at least one of the following: adding a new value to the target position, removing the current value from the target object, utilizing the new value to replace the current value at the target position, merging the new value with the current value at the target position and inserting the target position, and moving the current value from one position to another. In some embodiments, the mapping operation includes a reference to a mapping function and the parameter of the mapping function.
[0036] Figure 3 FIG. 3 is a schematic diagram showing an example 300 of a mapping description document according to some embodiments of the present disclosure. Figure 3 As shown, example 300 includes a mapping description document 302, which includes an array, and the array includes multiple mapping operations stored in sequence, namely, a removal operation 304, a replacement operation 306, an addition operation 308, and a move operation 310. The mapping operation is the basic object of the mapping operation document, and each operation describes the source interface specification document (e.g., Figure 1 The generic interface specification 114 shown in FIG. 1 is adapted to form a target interface specification document (eg, Figure 1 Each mapping operation object consists of several members (as parameters of the mapping operation). Some members are required, while some members are optional, and some members are only valid for specific types of operations. The following Table 1 shows the members available in some embodiments:
[0037]
[0038] Table 1
[0039] In example 300, JSONPath may be used to locate one or more target locations in a source interface specification. An example of a JSONPath expression is "$.store.book[0].title".
[0040] As shown in Table 1 above, the types of mapping operations may include "add", "remove", "replace", "assign", and "move". The "add" operation can add a new value to the target location. The target location can be an array or an object, and if an index is specified in the path string, the value object will be inserted at the index. If the target location already has a current value, the current value will be replaced by the new value. In some embodiments, the mapping function of the "add" operation can accept multiple inputs. The "remove" operation can remove a value from the target object. If the specified path cannot resolve any valid object, the "remove" operation fails. If the resolved target object is an element in an array, all elements after the removed element will be moved forward. The "replace" operation can replace the current value at the target location with a given new value, and if the target location does not exist, the target location can be added. The "assign" operation is similar to the "replace" operation, but during the "assign" operation, the given new value will be merged with the current value at the target location before being inserted into the target location (commonly used in scenarios where only some minor changes to the current value are required). The "move" operation can move a value from one location to another, and if the source location does not exist, the "move" operation fails.
[0041] like Figure 3 As shown, a mapping function can be used in a mapping operation (for example, by adding a mapper member and a mapperContext member in operation 308). The mapping function is used to map requests from the client (front-end interface) to the server (back-end interface) at runtime, and to map responses from the server to the client. The mapping function can be defined in a separate file using any programming language. The mapper member in a mapping operation can accept one or more inputs, which are defined by the mapperContext member of the operation object.
[0042] In this way, the conversion relationship between the original interface specification (i.e., the back-end interface specification or the general interface specification) and the target interface specification (i.e., the front-end interface specification) can be described using predefined rules and a small amount of code, thereby reducing the time and labor costs consumed in developing new interfaces. In addition, the mapping description document can also be reused to generate similar front-end interface specifications for other clients, thereby further saving time and labor costs.
[0043] In some embodiments, when generating the front-end interface specification, objects in the general interface specification can be updated based on the mapping operations in the mapping description document, and then tags can be added to the updated objects, indicating the mapping between the updated objects and the objects before the update. Figure 4 FIG. 4 is a schematic diagram showing an example process 400 for generating a front-end interface specification for a front-end interface according to some embodiments of the present disclosure. Figure 4 As shown, at block 402, process 400 may read a mapping operation from a mapping description document. Figure 1 In the illustrated environment 100, the converter 124 can read the mapping operations 118 from the mapping description document 116. At block 404, the process 400 can determine whether all mapping operations have been processed. Figure 1 In the illustrated environment 100 , the converter 124 may determine whether all of the mapping operations 118 - 1 through 118 -N in the mapping description document 116 have been processed. If there are unprocessed mapping operations in the mapping operations 118 - 1 through 118 -N, the process 400 proceeds to block 406 .
[0044] At block 406, process 400 may perform a mapping operation according to a mapping description of the mapping operation. Figure 1 In the illustrated environment 100, the converter 124 may perform a mapping operation according to a description of a mapping operation 118 in a mapping description document 116. The mapping description document 116 may be, for example, Figure 3 As shown in the mapping description document 302, the mapping operation 118-1 may be, for example, Figure 3 The illustrated removal operation 304. The converter 124 may perform a mapping operation based on the values of the various members defined in the removal operation 304, for example.
[0045] In box 408, process 400 can add custom attributes as internal tags to the operated object. Since the object in the front-end interface specification has been updated, it is necessary to maintain the mapping between the updated object in the front-end interface specification and the original object in the general interface specification. Therefore, process 400 can add custom attributes to the operated object after performing a mapping operation on the original object in the general interface specification, and the custom attributes can indicate the mapping between the updated object and the original object. Then, process 400 returns to box 404 to redetermine whether all mapping operations have been processed. If all mapping operations have been processed, process 400 proceeds to box 410. In box 410, process 400 can generate a front-end interface specification for the front-end interface. For example, in Figure 1 In the illustrated environment 100 , after all mapping operations 118 are processed sequentially, the converter 124 may generate a front-end interface specification 126 for the client 108 .
[0046] In this way, a new front-end interface specification can be generated based on the general interface specification and the mapping description document, so that a client-specific front-end interface can be provided to meet the client's specific requirements for the interface.
[0047] FIG. 5A to FIG. 5C A schematic diagram showing an example general interface specification 500, an example mapping description document 510, and an example mapping function configuration document 520 for generating a new front-end interface specification based on a general interface specification using a mapping description document according to some embodiments of the present disclosure. FIG. 5A to FIG. 5C In the example shown, the current product has provided a backend interface, which is defined by the general interface specification 500. Then, a new set of frontend interfaces needs to be provided for a new type of client of the product. In the backend interface, on the one hand, an integer error code is used as an error message, and on the other hand, a parameter "CorrelationID" is placed in the header of the request. The requirements of the new type of client are to use human-readable statements as error messages and to place the "CorrelationID" parameter in the query parameters of the request.
[0048] Figure 5A An example general interface specification 500 defining a backend interface according to an embodiment of the present disclosure is shown. Figure 5A As shown, in the general interface specification 500, a schema (i.e., "schemas") is defined in box 502, and the schema includes a data structure "ErrorMsg", the type of "ErrorMsg" is "object" (i.e., "object"), the attributes include "code" (i.e., "code"), and the type of the code is "integer" (i.e., "integer"). Parameters are defined in box 504, including a parameter "CorrelationId", which represents the identifier of the tenant, the location where the parameter is passed in is the "header" (i.e., "header") of the request, and the schema type of the parameter is "string" (i.e., "string"). The endpoint " / api / v1 / foobars" is defined in box 506, which includes a GET method, the parameters of the GET method reference the parameter "CorrelationID" in box 504, and its response includes a code "400", and its schema references the schema "ErrorMsg" in box 502.
[0049] Figure 5B FIG. 5 shows an example mapping description document 510 for converting a general interface specification 500 into a new front-end interface specification according to an embodiment of the present disclosure. Figure 5BAs shown, the mapping description document 510 includes an array, which stores the "assign" operation 512, the "remove" operation 514 and the "add" operation 516 in order. First, the position where the parameter "CorrelationID" is passed in the request is changed from "header" to "query". In the "assign" operation 512, the member "op" specifies that the operation type is "assign", the member "paths" specifies the position of the target object to be updated by the "assign" operation 512 (i.e., the "CorrelationID" parameter under "parameters" under "component" in the general interface specification 500), and the member "value" specifies that the position of the passed-in parameter (i.e., "in") is "query" (i.e., "query"). It can be seen that the role of the "assign" operation 512 is to assign a new value "query" to the position of the passed-in parameter of the parameter "CorrelationID".
[0050] Then, in order to change the returned error message from an error code to a human-readable statement, the property of the "ErrorMsg" mode can be changed from "code" to "string", and a mapping function can be used to return the corresponding string according to the value of the code. Figure 5B As shown, after the "assign" operation 512, there is a "remove" operation 514. In the "remove" operation 514, the member "op" specifies that the operation type is "remove", and the member "paths" specifies the location of the target object to be updated by the "remove" operation 514 (i.e., the "code" property under "properties" under "ErrorMsg" under "schemas" under "component" in the general interface specification 500). It can be seen that the role of the "remove" operation 514 is to remove the "code" property of the schema "ErrorMsg".
[0051] like Figure 5BAs shown, the "remove" operation 514 is followed by the "add" operation 516. In the "add" operation, the member "op" specifies that the operation type is "add", and the member "paths" specifies where the "add" operation 516 is to add content (i.e., the "message" property under "properties" under "ErrorMsg" under "schemas" under "components"). The member "mapper" specifies the name of the referenced mapping function (i.e., "errorMsgMapper"). The member "mapperContext" specifies the schema of the parameters to be passed into the mapping function (i.e., "ErrorMsg"). The member "value" specifies the value to be added to the "message" property (i.e., the type is "string"). It can be seen that the role of the "add" operation 516 is to add the "message" attribute to the "ErrorMsg" pattern, the category of the "message" attribute is "string", and the mapping function "errorMsgMapper" implements the conversion method between the "ErrorMsg" pattern in the general interface specification 500 and the "ErrorMsg" pattern in the new front-end interface specification.
[0052] Figure 5C An example mapping function configuration document 520 according to some embodiments of the present disclosure is shown. As shown in FIG5 , the implementation of the mapping function "errorMsgMapper" is defined in the mapping function configuration document 520. In this implementation, if the error message code returned by the back-end interface is "401", the new front-end interface returns the converted string "Unauthorized!" ("Unauthorized!"); otherwise, no matter what the error message code returned by the back-end interface is, the new front-end interface returns the string "Unknown Error." ("Unknown error.").
[0053] In this way, a new front-end interface specification can be generated based on the general interface specification 500 and the mapping description document 510, and the mapping function configuration document 520 can be used to implement the conversion logic between the complex back-end interface and the front-end interface in the front-end interface specification, thereby meeting more requirements from different clients and improving user satisfaction.
[0054] In some embodiments, when converting a front-end request into a back-end request that calls a back-end interface, the front-end request can be verified based on the front-end interface specification. In some embodiments, a back-end request can be sent to a server, and then back-end response information associated with the general interface specification can be received from the server. In some embodiments, the back-end response can be converted into a front-end response associated with the front-end interface specification based on the front-end interface specification and the mapping function configuration document. In some embodiments, the front-end response can be verified based on the first front-end interface specification, and then the front-end request can be responded to using the front-end response.
[0055] Figure 6 FIG. 6 is a schematic diagram showing an example process 600 of using a generated interface specification document and a mapping function configuration document for a front-end interface to respond to a request from a client according to some embodiments of the present disclosure. Figure 6 As shown, at block 604, process 600 may utilize a front-end interface specification 606 (e.g., Figure 1 126) to verify the front-end request 602 from the client (e.g., Figure 1 608). For example, the process 600 may verify whether the format of the front-end request 602 complies with the request format defined in the front-end interface specification 606. Then, in box 610, the process 600 may convert the verified front-end request 602 into a back-end request 612 using the front-end interface specification 606 and the mapping function configuration document 608. In box 614, the process 600 may send the back-end request 612 to the back-end server 618 and obtain a back-end response 620 from the back-end server 618, and both the back-end request 612 and the back-end response 620 comply with the definition of the back-end interface in the general interface specification 616. In box 622, the process 600 may convert the back-end response 620 into a front-end response 626 based on the front-end interface specification 606 and the mapping function configuration document 608. Before returning the front-end response 626 to the client, in box 624, the process 600 may verify the front-end response 626 using the front-end interface specification 606. For example, process 600 can verify whether the format of front-end response 626 conforms to the response format defined in front-end interface specification 606 .
[0056] In this way, the format of the request from the client and the format of the response returned to the client can be verified, thereby improving the stability of the system. In addition, the conversion between the front-end request and the back-end request can be realized, so that the back-end server can provide the corresponding response. In addition, the conversion between the back-end response and the front-end response can be realized, so that the client can obtain the response that meets its needs, thereby improving customer satisfaction.
[0057] Figure 7Schematic block diagram of an example device 700 that can be used to implement embodiments of the present disclosure is shown. Figure 1 The servers of the backend services 102 and 104 shown may be such as Figure 7 The example device 700 shown. As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 702 or loaded from a storage unit 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0058] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0059] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as method 200. For example, in some embodiments, the method 200 may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the computing unit 701, one or more steps of the method 200 described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to perform the method 200 in any other appropriate manner (e.g., by means of firmware).
[0060] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chip systems (SOCs), load programmable logic devices (CPLDs), and the like.
[0061] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0062] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In addition, although each operation is depicted in a specific order, this should be understood as requiring such operations to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain the desired result. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Certain features described in the context of separate embodiments can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination.
[0063] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A method for providing an interface, comprising: Get the common interface specification associated with the backend interface; generating a first front-end interface specification based on the general interface specification and a first mapping, wherein the first mapping indicates a conversion relationship between the general interface specification and the first front-end interface specification; converting a first front-end request into a first back-end request associated with the back-end interface based on the first front-end interface specification; generating a second front-end interface specification based on the general interface specification and a second mapping, the second mapping indicating a relationship between the general interface specification and the second front-end interface specification, the first front-end interface specification being different from the second front-end interface specification; and The second front-end request is converted into a second back-end request associated with the back-end interface based on the second front-end interface specification.
2. The method according to claim 1, wherein generating the first front-end interface specification based on the general interface specification and the first mapping comprises: updating an object in the general interface specification based on a mapping operation in the first mapping; as well as A tag is added to the updated object, the tag indicating a mapping between the updated object and the object before updating.
3. The method according to claim 1, wherein the mapping operations in the first mapping and the second mapping include: A mapping operation indicator indicating the type of the mapping operation and a path specifying the location of a target object to be operated on.
4. The method according to claim 3, wherein the type of the mapping operation comprises at least one of the following: Adds a new value to a target location, removes the current value from the target object, replaces the current value at the target location with the new value, merges the new value with the current value at the target location and inserts it at the target location, and moves the current value from one location to another.
5. The method according to claim 4, wherein the mapping operation in the first mapping comprises a reference to a mapping function and parameters of the mapping function, and the method further comprises: Obtaining a mapping function configuration document that implements the mapping function; as well as The first front-end request is converted into the first back-end request associated with the back-end interface based on the first front-end interface specification and the mapping function configuration document.
6. The method of claim 5, wherein converting the first front-end request into the first back-end request associated with the back-end interface based on the first front-end interface specification and the mapping function configuration document comprises: The first front-end request is validated based on the first front-end interface specification.
7. The method according to claim 6, wherein the method further comprises: Sending the first backend request to the server; as well as Backend response information associated with the general interface specification is received from the server.
8. The method according to claim 7, wherein the method further comprises: The backend response is converted into a frontend response associated with the first frontend interface specification based on the first frontend interface specification and the mapping function configuration document.
9. The method according to claim 8, wherein the method further comprises: verifying the front-end response based on the first front-end interface specification; as well as The first front-end request is responded to with the front-end response.
10. An electronic device comprising: at least one processor; as well as a memory coupled to the at least one processor and having instructions stored thereon, the instructions, when executed by the at least one processor, causing the electronic device to perform actions, the actions comprising: Get the common interface specification associated with the backend interface; generating a first front-end interface specification based on the general interface specification and a first mapping, wherein the first mapping indicates a conversion relationship between the general interface specification and the first front-end interface specification; converting a first front-end request into a first back-end request associated with the back-end interface based on the first front-end interface specification; generating a second front-end interface specification based on the general interface specification and a second mapping, the second mapping indicating a relationship between the general interface specification and the second front-end interface specification, the first front-end interface specification being different from the second front-end interface specification; and The second front-end request is converted into a second back-end request associated with the back-end interface based on the second front-end interface specification.
11. The device according to claim 10, wherein generating the first front-end interface specification based on the general interface specification and the first mapping comprises: updating an object in the general interface specification based on a mapping operation in the first mapping; as well as A tag is added to the updated object, the tag indicating a mapping between the updated object and the object before updating.
12. The apparatus according to claim 10, wherein the mapping operations in the first mapping and the second mapping include: A mapping operation indicator indicating the type of the mapping operation and a path specifying the location of a target object to be operated on.
13. The apparatus of claim 12, wherein the type of the mapping operation comprises at least one of the following: Adds a new value to a target location, removes the current value from the target object, replaces the current value at the target location with the new value, merges the new value with the current value at the target location and inserts it at the target location, and moves the current value from one location to another.
14. The apparatus of claim 13, wherein the mapping operation in the first mapping comprises a reference to a mapping function and parameters of the mapping function, and the actions further comprise: Obtaining a mapping function configuration document that implements the mapping function; as well as The first front-end request is converted into the first back-end request associated with the back-end interface based on the first front-end interface specification and the mapping function configuration document.
15. The apparatus of claim 14, wherein converting the first front-end request into the first back-end request associated with the back-end interface based on the first front-end interface specification and the mapping function configuration document comprises: The first front-end request is validated based on the first front-end interface specification.
16. The apparatus of claim 15, wherein the actions further comprise: Sending the first backend request to the server; as well as Backend response information associated with the general interface specification is received from the server.
17. The apparatus of claim 16, wherein the actions further comprise: The backend response is converted into a frontend response associated with the first frontend interface specification based on the first frontend interface specification and the mapping function configuration document.
18. The apparatus of claim 17, wherein the actions further comprise: verifying the front-end response based on the first front-end interface specification; as well as The first front-end request is responded to with the front-end response.
19. A computer program product tangibly stored on a non-transitory computer readable medium and comprising machine executable instructions which, when executed, cause a machine to: Get the common interface specification associated with the backend interface; generating a first front-end interface specification based on the general interface specification and a first mapping, wherein the first mapping indicates a conversion relationship between the general interface specification and the first front-end interface specification; converting a first front-end request into a first back-end request associated with the back-end interface based on the first front-end interface specification; generating a second front-end interface specification based on the general interface specification and a second mapping, the second mapping indicating a relationship between the general interface specification and the second front-end interface specification, the first front-end interface specification being different from the second front-end interface specification; and The second front-end request is converted into a second back-end request associated with the back-end interface based on the second front-end interface specification.
20. The computer program product of claim 19, wherein generating the first front-end interface specification based on the general interface specification and the first mapping comprises: updating an object in the general interface specification based on a mapping operation in the first mapping; as well as A tag is added to the updated object, the tag indicating a mapping between the updated object and the object before updating.