CN115904317A - Method, device, equipment and storage medium for uniformly calling front-end interface and back-end interface - Google Patents

Method, device, equipment and storage medium for uniformly calling front-end interface and back-end interface Download PDF

Info

Publication number
CN115904317A
CN115904317A CN202211394462.7A CN202211394462A CN115904317A CN 115904317 A CN115904317 A CN 115904317A CN 202211394462 A CN202211394462 A CN 202211394462A CN 115904317 A CN115904317 A CN 115904317A
Authority
CN
China
Prior art keywords
interface
api
request
unified
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211394462.7A
Other languages
Chinese (zh)
Inventor
王颖奇
冯斌
李青昊
董正选
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Fulin Technology Co Ltd
Original Assignee
Shenzhen Fulin Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Fulin Technology Co Ltd filed Critical Shenzhen Fulin Technology Co Ltd
Priority to CN202211394462.7A priority Critical patent/CN115904317A/en
Publication of CN115904317A publication Critical patent/CN115904317A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application discloses a method, a device, equipment and a storage medium for uniformly calling front and back end interfaces, and belongs to the technical field of software development. According to the method, the unified interface service is installed in the front-end and back-end development environments, and the unified interface service generates the AP I interface with a unified front-end and back-end format; when a call request of an AP I interface is received, checking the call request; if the call request passes the inspection, acquiring request parameters, creating a service logic through the request parameters, and returning request call success information after the service logic creation is completed; and if the calling request does not pass the check, acquiring check exception information and outputting the check exception information. The front-end interface and the back-end interface are defined in a unified mode, AP I logic can be defined in a unified mode through the front end and the back end, the front-end interface and the back-end interface are reduced in butt joint work and synchronous work, synchronous verification can be achieved through calling of the front-end interface and the back-end interface, the front-end and back-end development workload is reduced, and development efficiency is improved.

Description

Method, device, equipment and storage medium for uniformly calling front-end interface and back-end interface
Technical Field
The application belongs to the technical field of software development, and particularly relates to a method, a device, equipment and a storage medium for unified calling of front and back end interfaces.
Background
When the existing plug-in or component of the web project based on the Javascript/TypeScript full stack is used for API definition, calling or implementation, the front end and the back end need to separately process respective API definition, calling and implementation, and the common node.
Therefore, a plurality of problems affecting the development efficiency can occur in the development process of the front end and the back end, for example, when the back end of the API is not implemented temporarily, the front end needs to process Mock data according to the API document; after the development of the back end is finished, the front end needs to take time alone to perform the butt joint work of the interface; if the API is changed, the front end may not be synchronized in time, so that unnecessary development work is caused; the API type definition has one copy at the front end/the back end and needs to be repeatedly declared; when a new API is added or API changes occur, the back end needs to perform new permission/parameter verification independently according to each new API structure statement; the back end API Error and the front end are not unified, and the front end and the back end have repeated front end and back end Error codes and the like during each development.
Disclosure of Invention
The embodiment of the application aims to provide a method and a device for uniformly calling front-end and back-end interfaces, computer equipment and a storage medium, so as to solve the technical problems of large workload and low development efficiency of the existing scheme that the front end and the back end need to separately process definition and calling/realizing of an API.
In order to solve the above technical problem, an embodiment of the present application provides a unified call of front and back end interfaces, and adopts the following technical scheme:
a unified calling method for front-end and back-end interfaces comprises the following steps:
installing a uniform interface service, and generating an API interface with a uniform front-end and back-end format by the uniform interface service, wherein the uniform interface service is a pre-developed plug-in for uniformly defining the front-end and back-end API;
receiving a calling request of the API, and judging whether the calling request passes the inspection;
if the call request passes the inspection, acquiring a request parameter, creating a service logic through the request parameter, and returning request call success information after the service logic creation is completed;
and if the calling request does not pass the inspection, acquiring abnormal inspection information and outputting the abnormal inspection information.
Further, the installing the unified interface service, generating an API interface with a unified front-end format and a unified back-end format by the unified interface service, specifically includes:
calling an API definition function in the unified interface service;
generating an initial API interface path based on the API definition function and input API interface parameters;
performing path conversion on the initial API path to obtain a conversion path of the API;
and adding a preset interface unified identifier into a conversion path of the API interface to generate the API interface with a unified front-end format and a unified back-end format.
Further, the generating an initial API interface path based on the API definition function and the input API interface parameter specifically includes:
determining a preset API variable declaration rule based on the API definition function;
and combining the API interface parameters according to the API variable declaration rule to obtain the initial API interface path.
Further, the performing path conversion on the initial API interface path to obtain a conversion path of the API interface specifically includes:
matching and identifying the character to be converted in the initial API path through a regular expression;
and replacing the character to be converted in the initial API interface path by a preset replacing character to obtain a conversion path of the API interface.
Further, the receiving a call request of the API interface and determining whether the call request passes the check specifically includes:
acquiring interface information of the API with the uniform front-end format and the back-end format, and constructing a corresponding verification middleware according to the interface information;
and checking the calling request based on the checking middleware, wherein the checking comprises permission checking, parameter checking, repeated checking and timeout checking.
Further, the obtaining of the request parameter, creating a service logic through the request parameter, and returning a request call success message after the service logic creation is completed specifically includes:
analyzing the call request to obtain request parameters in the call request;
creating a service logic according to the request parameter, and generating the request call success information after the service logic creation is completed;
carrying out standardized encapsulation on the request calling success information to obtain request calling success information with a uniform format;
and outputting the request calling success information in the uniform format.
Further, the obtaining of the check exception information and outputting of the check exception information specifically include:
acquiring the abnormal checking information at the back end, and serializing the abnormal checking information to obtain an error case;
sending the error instance to a front end, performing deserialization on the error instance at the front end, and restoring the check abnormal information;
and outputting the abnormal checking information at the front end.
In order to solve the above technical problem, an embodiment of the present application further provides a unified call of front and back end interfaces, where the following technical scheme is adopted:
a front-back interface unified calling device comprises:
the system comprises a unified interface service module, a front-end API interface and a back-end API interface, wherein the unified interface service module is used for installing a unified interface service and generating the front-end API interface and the back-end API interface with unified formats by the unified interface service, and the unified interface service is a pre-developed plug-in for unified definition of the front-end API and the back-end API;
the request checking module is used for receiving the calling request of the API and judging whether the calling request passes the checking;
the first verification result module is used for acquiring request parameters when the call request passes the verification, creating service logic through the request parameters, and returning request call success information after the service logic is created;
and the second check result module is used for acquiring check exception information and outputting the check exception information when the calling request fails to pass the check.
In order to solve the above technical problem, an embodiment of the present application further provides a computer device, which adopts the following technical solutions:
a computer device comprises a memory and a processor, wherein the memory stores computer readable instructions, and the processor executes the computer readable instructions to realize the steps of the front-end and back-end interface unified calling method.
In order to solve the above technical problem, an embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solutions:
a computer readable storage medium having computer readable instructions stored thereon which, when executed by a processor, implement the steps of the method for unified invocation of a front-back interface as described above.
Compared with the prior art, the embodiment of the application mainly has the following beneficial effects:
the application discloses a method, a device, equipment and a storage medium for unified calling of front-end and back-end interfaces, and belongs to the technical field of software development. According to the application, the unified interface service is installed in the front-end and back-end development environments, and the unified interface service generates the API interface with the unified front-end and back-end formats; when a call request of an API (application program interface) is received, checking the call request; if the call request passes the inspection, acquiring a request parameter, creating a service logic through the request parameter, and returning request call success information after the service logic creation is completed; and if the calling request does not pass the check, acquiring check exception information and outputting the check exception information. The front-end interface and the back-end interface are uniformly defined, the reusable uniform definition API logic of the front end and the back end is achieved, the front-end interface and the back-end interface are reduced in butt joint work and synchronous work, meanwhile, the front-end interface and the back-end interface can call synchronous verification, the front-end and the back-end development workload is reduced, and the development efficiency is improved.
Drawings
In order to more clearly illustrate the solution of the present application, the drawings needed for describing the embodiments of the present application will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present application, and that other drawings can be obtained by those skilled in the art without inventive effort.
FIG. 1 illustrates a system framework diagram of an exemplary unified front-end API and Error definitions to which the present application may be applied;
FIG. 2 illustrates a flow diagram for one embodiment of a front-back interface unified call method according to the present application;
FIG. 3 illustrates a flow diagram of another embodiment of a front-back interface unified call method according to the present application;
FIG. 4 is a block diagram illustrating one embodiment of a front-back interface unified invocation apparatus according to the present application;
FIG. 5 shows a schematic block diagram of one embodiment of a computer device according to the present application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "including" and "having," and any variations thereof, in the description and claims of this application and the description of the above figures are intended to cover non-exclusive inclusions. The terms "first," "second," and the like in the description and claims of this application or in the above-described drawings are used for distinguishing between different objects and not for describing a particular order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase 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. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
In order to make the technical solutions better understood by those skilled in the art, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
At present, a front-end and back-end development usually adopt a framework with separated front and back ends, when an API is realized/defined/called, the front and back ends need to separately process the definition and calling/realizing of the API, so that a plurality of problems affecting development efficiency can occur in the front-end and back-end development processes, for example, the front end needs to process Mock data, the back end needs to separately perform the butt joint work of an interface, the front-end and back-end APIs cannot realize synchronous change, the API type definition needs to be repeatedly declared, when a new API is added or changed, the back end needs to separately perform new verification according to each new API structure statement, the front and back ends can have repeated front and back-end Error codes and the like when the API is developed each time.
In order to solve the above technical problem, in a specific embodiment of the present application, please refer to fig. 1, which discloses a framework defined by unified front-end and back-end APIs and Error based on Javascript/TypeScript, including a unified interface server 101, a Web front-end 102, a Node back-end route 103, and a verification middleware 104, where the unified definition is implemented on the API and the Error by the unified interface server 101, so that the front-end and back-end can repeatedly define API logic and unified Error instances, reduce the front-end and back-end interface docking work and synchronization work, and simultaneously complete the synchronization verification of the authority, parameters, repetition, timeout and other indexes when the interface API is called by the verification middleware 104, thereby reducing the front-end and back-end development workload and improving the development efficiency.
The unified interface server 101 is responsible for unified definition of API and Error, and is independent of the Web front end 102 and Node back end route 103, and includes a defineAPI function, an APIError basic type and a fillupath component, where:
the defineAPI function is used for defining an API, and the defineAPI comprises field information such as HTTP Method, request Params, request Body, response Body, path Params and Extra (Permission Point).
The API error basic type is used for basic API exception definition, including permissioned exception error, invalidParamsError, timeOutError, etc. thrown by the back end, and the front end can take corresponding information exceptions. It should be noted that, an exception that is not inherited from the APIError basic type will not be thrown by the back-end, in which case the back-end API will uniformly print a log and expose an error that the front-end displays the lnnalserver error (500).
The fillupath component is used for constructing and uniformly exporting the API, the fillupath component can add a uniform prefix mark on the API path to realize uniform front-end and back-end API, and the prefix mark is/API/v 1. The fillupath component may also classify front and back end APIs to obtain subdivided API Groups.
The Web front end 102 contains relevant toolsets of front-end call APIs, including fetchAPI functions and useFetchAPI functions, where:
the fetchAPI function can directly call all APIs defined in the unified interface server 101, type prompts and return value types related to all API parameter definitions can be seen in the calling process, corresponding HTTP Response can be returned after the API function is used, and if API exception occurs, the same error type as the back end can be obtained at the front end.
The useFetchAPI function provides hooks for the reac, and the useFetchAPI comprises all functions of the fetchAPI and provides the functions of loading state and the fetch.
Node back-end route 103 contains basic tools for API implementation, including a router.
The Route tool is used for the specific implementation of API Route, and here, any API defined in the unified interface server 101 can be directly used, and the implementAPI automatically verifies various parameters in the HTTP Request according to the API definition, such as: body, URL Params, etc., and will execute the corresponding authentication logic according to the authority definition in the API. In the callback of the implementationapi, the specific implementation callback of Route can take parameters with safe types, and can also obtain various external dependencies required by unified injection. It should be noted that all exceptions thrown here will be handled and logged uniformly, inherited from APIError will be captured by the front end.
The createRoute tool is used for creating a Router instance, which can be used for API implementation as described above, and can also be added with various custom midleware, such as custom permission/parameter/repeat request/timeout check, etc.
The on tool is used for registering global events, such as request, error and the like, and can conveniently realize error and call monitoring in the global.
In the embodiment, the unified definition of the front-end interface and the back-end interface is realized through a set of unified front-end and back-end API and Error defined framework, so that the unified API logic of the front end and the back end can be reused, the butt joint work and the synchronous work of the front-end and back-end interfaces are reduced, meanwhile, the synchronous verification of the calling of the front-end and back-end interfaces can be realized, the workload of the front-end and back-end development is reduced, and the development efficiency is improved.
With continued reference to FIG. 2, a flow diagram of one embodiment of a method for unified invocation of a front-back interface in accordance with the present application is shown. The unified calling method of the front-end interface and the back-end interface comprises the following steps:
s201, installing a uniform interface service, and generating an API interface with a uniform front-end and back-end format by the uniform interface service, wherein the uniform interface service is a pre-developed plug-in for uniformly defining the front-end and back-end API.
In this embodiment, on the basis of the existing front-back end development framework, a set of unified front-back end interface API and abnormal Error definition framework is constructed in advance, wherein a unified interface service plug-in developed in advance is installed, the unified interface service is respectively connected with the front end and the back end, the unified interface service is a plug-in used for realizing unified definition for the front-back end API and the Error, and after developers input front-back end API interface parameters and development requirements, the unified interface service is unified to define the front-back end API and the Error in a unified manner.
In the previous development mode, the backend is often required to provide Swagger or API documents and the like for the front end to refer to the calling method and parameters of the API, and a great deal of energy is required to configure Swagger or write API documents. However, in the development mode of the framework, the reusable API of the front end and the back end defines logic through the deep combination of the API of the front end and the back end, so that the front end can directly call the back end interface in a fetchAPI function mode. And the frame also encapsulates functions such as error processing and parameter processing, and further encapsulates the frame in combination with read Hooks.
In the above embodiment, the front-end API and the Error are defined uniformly by the uniform interface service, so that the front-end API and the back-end API are deeply combined.
Further, installing a unified interface service, and generating an API interface with a unified front-end format and a unified back-end format by the unified interface service, specifically including:
calling an API definition function in the unified interface service;
generating an initial API interface path based on the API definition function and the input API interface parameters;
performing path conversion on the initial API path to obtain a conversion path of the API;
and adding a preset interface unified identifier into a conversion path of the API interface to generate the API interface with a unified front-end format and a unified back-end format.
In this embodiment, an API variable declaration rule agreed in advance by a defineAPI function is used, after a developer inputs API interface parameters, the defineAPI function in a unified interface service is called, the input API interface parameters are combined according to an API definition function to generate an initial API interface path, the initial API interface path is subjected to path conversion, part of special symbols in the initial API interface path are converted to obtain a conversion path of an API interface, and finally, a preset interface unified identifier is added to the conversion path of the API interface through a fillupath component to generate an API interface with a unified front-end format and a unified back-end format.
In the embodiment, the method and the device process the input API interface parameters through the API definition function to obtain the initial API interface path, and realize the unified definition of the front-end and back-end API interfaces by performing path conversion on the initial API interface path and adding the interface unified identification.
Further, generating an initial API interface path based on the API definition function and the input API interface parameters specifically includes:
determining a preset API variable declaration rule based on the API definition function;
and combining the API interface parameters according to the API variable declaration rule to obtain an initial API interface path.
It should be noted that, the development framework generally pre-stipulates the variable declaration rule of the API, for example, the variable declaration rule of the API is a combination of characters + double underlines + single underlines, and in one development, an initial API interface path generated after the developer inputs API interface parameters is "const org _ create _ user = defineAPI ()".
In this embodiment, a predetermined API variable declaration rule is determined based on the API definition function, and API interface parameters are combined according to the API variable declaration rule to obtain an initial API interface path.
Further, performing path conversion on the initial API interface path to obtain a conversion path of the API interface, which specifically includes:
matching and identifying the character to be converted in the initial API path through a regular expression;
and replacing the character to be converted in the initial API interface path by a preset replacing character to obtain the conversion path of the API interface.
In the present embodiment, the preset characters to be converted include "\\" and "_", the preset substitutes include "/" and "-", the single underline is matched by the regular expression and replaced with a short horizontal line, and the double underline is replaced with a slash, as in the above embodiment, the initial API interface path is "const org _ create _ user = defineeapi ()" the conversion path of the API interface "const org _ create _ user = defineeapi ("/org/create-user ")" after symbol replacement is completed.
In the above embodiment, since the front-end and back-end development environments do not allow the use of "/" and "-" for programming, after the initial API interface path is obtained, it is necessary to convert "\\" and "_" into "/" and "-", implement path conversion, automatically generate a conversion path of the API interface, and further reduce the work of developers.
It should be noted that, after obtaining the conversion path "const org _ create _ user = defineAPI ("/org/create-user ")" of the API interface, a preset unified interface identifier is added to the conversion path of the API interface through the fileuppath component, and if the unified interface identifier is a prefix identifier/API/v 1, an API interface "/API/v1/org/create-user" with a unified front-end and back-end format is generated. The function expression form in the fillupath component is fillupath ("/API/v 1", APIs), "v1" is the current system version number, and "APIs" is any interface API, when the system version iterates, all interface API path addresses can be updated only by updating the current system version number, for example, when the current system version number is developed to "v2", all interface API path addresses can be updated by updating fillupath ("/API/v 2", APIs).
S202, receiving a call request of the API, and judging whether the call request passes the inspection.
In this embodiment, when the unified interface service generates an API interface with a uniform front-end and back-end format, a verification middleware corresponding to the API interface needs to be constructed, and when a call request of the API interface is received, the call request is verified by the verification middleware, including verifying authority information, request parameters, whether to repeat the request, and whether to time out the request in the call request.
In this embodiment, an electronic device (for example, a server shown in fig. 1) on which the front-back interface unified calling method operates may receive a calling request of the API interface through a wired connection manner or a wireless connection manner. It is noted that the wireless connection may include, but is not limited to, a 3G/4G connection, a WiFi connection, a bluetooth connection, a WiMAX connection, a Zigbee connection, a UWB (ultra wideband) connection, and other wireless connection now known or developed in the future.
In the embodiment, the application constructs the verification middleware corresponding to the API interface, verifies the call request through the verification middleware, and judges whether the API interface uniformly defined by the front end and the back end has call abnormality.
Further, receiving a call request of the API interface, and determining whether the call request passes the check, specifically including:
acquiring interface information of an API interface with a uniform front-end format and a uniform rear-end format, and constructing a corresponding verification middleware according to the interface information;
and checking the call request based on the checking middleware, wherein the checking comprises permission checking, parameter checking, repeated checking and overtime checking.
In this embodiment, interface information of an API interface with a uniform front-end format and a back-end format is obtained, where the interface information includes permission information, a request parameter, whether to repeat a request, and whether to request for timeout, and a corresponding verification middleware, such as a permission verifier, a parameter verifier, a repetition verifier, and a timeout verifier, is constructed according to the interface information, and the invocation request is verified by the verifier.
In the embodiment, the call request is verified by constructing the corresponding verification middleware, so that whether call exception exists in the API interface uniformly defined by the front end and the back end is judged.
S203, if the call request passes the verification, acquiring the request parameter, creating the service logic through the request parameter, and returning the request call success information after the service logic creation is completed.
In this embodiment, if the permission check, the parameter check, the repeat check, and the timeout check of the API call request all pass, the request parameter in the call request is obtained, the service logic is created through the request parameter, and the request call success information is returned after the service logic is created.
Further, acquiring a request parameter, creating a service logic through the request parameter, and returning request call success information after the service logic creation is completed, specifically including:
analyzing the call request, and acquiring a request parameter in the call request;
creating a service logic according to the request parameters, and generating request call success information after the service logic creation is completed;
carrying out standardized packaging on the request calling success information to obtain request calling success information in a uniform format;
and outputting request calling success information in a uniform format.
In this embodiment, when the permission check, the parameter check, the repeat check, and the timeout check of the API interface call request all pass, the call request is analyzed, the request parameter in the call request is obtained, the service logic is created according to the request parameter, the request call success information is generated after the service logic is created, the request call success information is subjected to standardized encapsulation, the request call success information in a uniform format is obtained, and the request call success information in a uniform format is output.
In the embodiment, the request calling success information in a unified format is obtained by performing standardized packaging on the request calling success information, and the request calling success information in the unified format is returned, so that the unified format of the returned information is realized, and the workload of front-end developers is further reduced.
And S204, if the calling request does not pass the check, acquiring check exception information and outputting the check exception information.
In this embodiment, when one or more of the permission check, the parameter check, the repetition check and the timeout check of the call request do not pass, it indicates that the API interface call request is abnormal, and then acquires the check abnormal information and outputs the check abnormal information.
Further, acquiring abnormal verification information and outputting the abnormal verification information, specifically comprising:
acquiring abnormal checking information at the back end, and serializing the abnormal checking information to obtain an error instance;
sending the error case to the front end, performing deserialization on the error case at the front end, and restoring and checking abnormal information;
and outputting the abnormal checking information at the front end.
Specifically, when the API interface call request is abnormal, obtaining abnormal verification information at the development back end, where the abnormal verification information includes no request permission, request parameter error, repeat request, and request timeout. And serializing the check abnormal information, performing sequence coding on the check abnormal information to obtain an error case, sending the error case to the front end, performing deserialization on the error case at the front end, decoding the error case, restoring the check abnormal information, and outputting the check abnormal information at the front end.
In the embodiment, the check abnormal information is obtained at the development back end, serialized, sent to the front end, deserialized at the front end, and restored, so that the same abnormal information is still obtained after network transmission, data transmission is facilitated through serialization and deserialization, and data loss can be prevented.
In a specific embodiment of the present application, please refer to fig. 3, the POST/API/USER/create API definition is created by the unified interface service, the USER API flow is created by definition at the front end, and the creation of the USER back end logic is implemented by definition. After a developer initiates a call request of an API (application program interface) through a front end, the call request is transmitted from the front end to a back end, the back end receives the call request, the call request is subjected to authority verification, parameter verification, repeated verification and overtime verification through a verification middleware, if the verification is passed, the call request is analyzed, request parameters in the call request are obtained, a service logic is created through the request parameters, and request call success information is returned after the service logic is created, so that the front end completes further processing; if one or more of the checks fail, the API interface calling request is indicated to have an exception, check exception information is obtained at the development back end, the check exception information is serialized to obtain an error instance, the error instance is sent to the front end, the error instance is deserialized at the front end, the check exception information is restored, and the exception information is output.
In the embodiment, the application discloses a unified calling method for front-end and back-end interfaces, and belongs to the technical field of software development. According to the application, the unified interface service is installed in the front-end and back-end development environments, and the unified interface service generates the API interface with a unified front-end and back-end format; when a call request of an API (application program interface) is received, checking the call request; if the call request passes the inspection, acquiring a request parameter, creating a service logic through the request parameter, and returning request call success information after the service logic creation is completed; and if the calling request does not pass the check, acquiring check exception information and outputting the check exception information. The front-end interface and the back-end interface are uniformly defined, the reusable uniform definition API logic of the front end and the back end is achieved, the front-end interface and the back-end interface are reduced in butt joint work and synchronous work, meanwhile, the front-end interface and the back-end interface can call synchronous verification, the front-end and the back-end development workload is reduced, and the development efficiency is improved.
It should be emphasized that, in order to further ensure the privacy and security of the request parameters, the request parameters may also be stored in a node of a block chain.
The block chain referred by the application is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware associated with computer readable instructions, which can be stored in a computer readable storage medium, and when executed, can include processes of the embodiments of the methods described above. The storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a Random Access Memory (RAM).
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and may be performed in other orders unless explicitly stated herein. Moreover, at least a portion of the steps in the flow chart of the figure may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
With further reference to fig. 4, as an implementation of the method shown in fig. 2, the present application provides an embodiment of a device for unified invocation of front and back end interfaces, where the embodiment of the device corresponds to the embodiment of the method shown in fig. 2, and the device may be specifically applied to various electronic devices.
As shown in fig. 4, the front-back interface unified invoking device 400 according to this embodiment includes:
the unified interface service module 401 is configured to install a unified interface service, and generate an API interface with a unified front-end format and a unified back-end format by the unified interface service, where the unified interface service is a pre-developed plug-in for unified definition of a front-end API and a back-end API;
a request checking module 402, configured to receive a call request of the API interface, and determine whether the call request passes checking;
a first verification result module 403, configured to, when the call request passes the verification, obtain a request parameter, create a service logic through the request parameter, and return a request call success message after the service logic creation is completed;
and a second check result module 404, configured to, when the call request fails to pass the check, obtain check exception information, and output the check exception information.
Further, the unified interface service module 401 specifically includes:
the function calling submodule is used for calling an API definition function in the unified interface service;
the path generation submodule is used for generating an initial API interface path based on the API definition function and the input API interface parameters;
the path conversion submodule is used for carrying out path conversion on the initial API interface path to obtain a conversion path of the API interface;
and the identification adding submodule is used for adding a preset uniform interface identification into the conversion path of the API interface to generate the API interface with uniform front and back end formats.
Further, the path generation sub-module specifically includes:
the declaration rule unit is used for determining a preset API variable declaration rule based on the API definition function;
and the path generation unit is used for combining the API interface parameters according to the API variable declaration rule to obtain an initial API interface path.
Further, the path conversion sub-module specifically includes:
the regular matching unit is used for identifying the character to be converted in the initial API interface path through regular expression matching;
and the symbol replacing unit is used for replacing the symbol to be converted in the initial API interface path through a preset replacing symbol to obtain the conversion path of the API interface.
Further, the request checking module 402 specifically includes:
the middleware construction sub-module is used for acquiring interface information of the API with uniform front and back end formats and constructing a corresponding verification middleware according to the interface information;
and the request checking submodule is used for checking the call request based on the checking middleware, wherein the checking comprises permission checking, parameter checking, repeated checking and overtime checking.
Further, the first verification result module 403 specifically includes:
the request analysis submodule is used for analyzing the calling request and acquiring request parameters in the calling request;
the logic creating submodule is used for creating a service logic according to the request parameters and generating request calling success information after the service logic is created;
the standardized packaging sub-module is used for carrying out standardized packaging on the request calling success information to obtain request calling success information in a unified format;
and the success information output submodule is used for outputting request call success information in a uniform format.
Further, the second verification result module 404 specifically includes:
the serialization sub-module is used for acquiring the abnormal verification information at the back end and serializing the abnormal verification information to obtain an error case;
the deserializing submodule is used for sending the error case to the front end, deserializing the error case at the front end and restoring the abnormal check information;
and the abnormal information output submodule is used for outputting the check abnormal information at the front end.
In the above embodiment, the application discloses a unified calling device for front and back end interfaces, and belongs to the technical field of software development. According to the application, the unified interface service is installed in the front-end and back-end development environments, and the unified interface service generates the API interface with a unified front-end and back-end format; when a call request of an API (application program interface) is received, checking the call request; if the call request passes the inspection, acquiring a request parameter, creating a service logic through the request parameter, and returning request call success information after the service logic creation is completed; and if the calling request does not pass the check, acquiring check exception information and outputting the check exception information. The front-end interface and the back-end interface are uniformly defined, the reusable uniform definition API logic of the front end and the back end is achieved, the front-end interface and the back-end interface are reduced in butt joint work and synchronous work, meanwhile, the front-end interface and the back-end interface can call synchronous verification, the front-end and the back-end development workload is reduced, and the development efficiency is improved.
In order to solve the technical problem, an embodiment of the present application further provides a computer device. Referring to fig. 5, fig. 5 is a block diagram of a basic structure of a computer device according to the present embodiment.
The computer device 5 comprises a memory 51, a processor 52, a network interface 53 communicatively connected to each other via a system bus. It is noted that only a computer device 5 having components 51-53 is shown, but it is understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead. As will be understood by those skilled in the art, the computer device is a device capable of automatically performing numerical calculation and/or information processing according to instructions set or stored in advance, and the hardware thereof includes but is not limited to a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device can be a desktop computer, a notebook, a palm computer, a cloud server and other computing devices. The computer equipment can carry out man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch panel or voice control equipment and the like.
The memory 51 includes at least one type of readable storage medium including a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the storage 51 may be an internal storage unit of the computer device 5, such as a hard disk or a memory of the computer device 5. In other embodiments, the memory 51 may also be an external storage device of the computer device 5, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the computer device 5. Of course, the memory 51 may also comprise both an internal storage unit of the computer device 5 and an external storage device thereof. In this embodiment, the memory 51 is generally used for storing an operating system and various application software installed in the computer device 5, such as computer readable instructions for uniformly invoking methods through front and back interfaces. Further, the memory 51 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 52 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 52 is typically used to control the overall operation of the computer device 5. In this embodiment, the processor 52 is configured to execute the computer readable instructions or processing data stored in the memory 51, for example, execute the computer readable instructions of the front-back interface unified calling method.
The network interface 53 may comprise a wireless network interface or a wired network interface, and the network interface 53 is generally used for establishing communication connections between the computer device 5 and other electronic devices.
The application discloses computer equipment belongs to software development technical field. According to the application, the unified interface service is installed in the front-end and back-end development environments, and the unified interface service generates the API interface with a unified front-end and back-end format; when a call request of an API (application program interface) is received, checking the call request; if the call request passes the inspection, acquiring a request parameter, creating a service logic through the request parameter, and returning request call success information after the service logic creation is completed; and if the calling request does not pass the check, acquiring check exception information and outputting the check exception information. The front-end interface and the back-end interface are uniformly defined, the reusable uniform definition API logic of the front end and the back end is achieved, the front-end interface and the back-end interface are reduced in butt joint work and synchronous work, meanwhile, the front-end interface and the back-end interface can call synchronous verification, the front-end and the back-end development workload is reduced, and the development efficiency is improved.
The present application further provides another embodiment, which is to provide a computer-readable storage medium storing computer-readable instructions executable by at least one processor to cause the at least one processor to perform the steps of the front-back interface unified call method as described above.
The application discloses a storage medium, and belongs to the technical field of software development. According to the application, the unified interface service is installed in the front-end and back-end development environments, and the unified interface service generates the API interface with a unified front-end and back-end format; when a call request of an API (application program interface) is received, checking the call request; if the call request passes the inspection, acquiring a request parameter, creating a service logic through the request parameter, and returning request call success information after the service logic creation is completed; and if the calling request does not pass the check, acquiring check exception information and outputting the check exception information. The front-end interface and the back-end interface are uniformly defined, the reusable uniform definition API logic of the front end and the back end is achieved, the front-end interface and the back-end interface are reduced in butt joint work and synchronous work, meanwhile, the front-end interface and the back-end interface can call synchronous verification, the front-end and the back-end development workload is reduced, and the development efficiency is improved.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present application.
It is to be understood that the above-described embodiments are merely illustrative of some, but not restrictive, of the broad invention, and that the appended drawings illustrate preferred embodiments of the invention and do not limit the scope of the invention. This application is capable of embodiments in many different forms and the embodiments are provided so that this disclosure will be thorough and complete. Although the present application has been described in detail with reference to the foregoing embodiments, it will be apparent to one skilled in the art that the present application may be practiced without modification or with equivalents of some of the features described in the foregoing embodiments. All equivalent structures made by using the contents of the specification and the drawings of the present application are directly or indirectly applied to other related technical fields, and all the equivalent structures are within the protection scope of the present application.

Claims (10)

1. A unified calling method for front and back end interfaces is characterized by comprising the following steps:
installing a uniform interface service, and generating an API interface with a uniform front-end and back-end format by the uniform interface service, wherein the uniform interface service is a pre-developed plug-in for uniformly defining the front-end and back-end API;
receiving a call request of the API, and judging whether the call request passes the inspection;
if the call request passes the inspection, acquiring a request parameter, creating a service logic through the request parameter, and returning request call success information after the service logic creation is completed;
and if the calling request does not pass the inspection, acquiring abnormal inspection information and outputting the abnormal inspection information.
2. The method for unified invocation of front-end and back-end interfaces according to claim 1, wherein the installing of the unified interface service and the generating of the API interface with unified front-end and back-end formats by the unified interface service specifically comprise:
calling an API definition function in the unified interface service;
generating an initial API interface path based on the API definition function and input API interface parameters;
performing path conversion on the initial API path to obtain a conversion path of an API;
and adding a preset uniform interface identifier into the conversion path of the API interface to generate the API interface with uniform front and back end formats.
3. The method for unified invocation of front-end and back-end interfaces according to claim 2, wherein the step of generating an initial API interface path based on the API definition function and the input API interface parameters specifically comprises:
determining a preset API variable declaration rule based on the API definition function;
and combining the API interface parameters according to the API variable declaration rule to obtain the initial API interface path.
4. The method for uniformly calling the front-end interface and the back-end interface according to claim 2, wherein the performing the path conversion on the initial API interface path to obtain the conversion path of the API interface specifically comprises:
matching and identifying the character to be converted in the initial API path through a regular expression;
and replacing the character to be converted in the initial API interface path by a preset replacing character to obtain a conversion path of the API interface.
5. The method for unified calling of the front-end and back-end interfaces according to claim 1, wherein the receiving the call request of the API interface and determining whether the call request passes the check specifically comprises:
acquiring interface information of the API with uniform front and back end formats, and constructing a corresponding verification middleware according to the interface information;
and verifying the calling request based on the verification middleware, wherein the verification comprises permission verification, parameter verification, repeated verification and timeout verification.
6. The method for unified invocation of a front-back end interface according to any of claims 1 to 5, wherein the obtaining of the request parameter, creating the service logic through the request parameter, and returning the request invocation success information after the creation of the service logic is completed specifically comprises:
analyzing the call request to obtain request parameters in the call request;
creating a service logic according to the request parameter, and generating the request call success information after the service logic creation is completed;
carrying out standardized encapsulation on the request calling success information to obtain request calling success information with a uniform format;
and outputting the request calling success information in the uniform format.
7. The method for unified invocation of a front-back interface according to claim 6, wherein the obtaining of the check exception information and the outputting of the check exception information specifically comprises:
acquiring the abnormal checking information at the back end, and serializing the abnormal checking information to obtain an error case;
sending the error instance to a front end, performing deserialization on the error instance at the front end, and restoring the check abnormal information;
and outputting the abnormal checking information at the front end.
8. The utility model provides a unified calling equipment of front and back end interface which characterized in that includes:
the system comprises a unified interface service module, a front end API interface and a back end API interface, wherein the unified interface service module is used for installing a unified interface service and generating an API interface with a unified front end format and a unified back end format by the unified interface service, and the unified interface service is a pre-developed plug-in for unified definition of the front end API and the back end API;
the request checking module is used for receiving the call request of the API and judging whether the call request passes the checking;
the first verification result module is used for acquiring request parameters when the call request passes the verification, creating service logic through the request parameters, and returning request call success information after the service logic is created;
and the second check result module is used for acquiring check exception information and outputting the check exception information when the calling request fails to pass the check.
9. A computer device comprising a memory having computer readable instructions stored therein and a processor that when executed performs the steps of the method for unified invocation by a front-back interface as recited in any of claims 1-7.
10. A computer readable storage medium having computer readable instructions stored thereon which, when executed by a processor, implement the steps of a front-back interface unified call method as claimed in any one of claims 1 to 7.
CN202211394462.7A 2022-11-08 2022-11-08 Method, device, equipment and storage medium for uniformly calling front-end interface and back-end interface Pending CN115904317A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211394462.7A CN115904317A (en) 2022-11-08 2022-11-08 Method, device, equipment and storage medium for uniformly calling front-end interface and back-end interface

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211394462.7A CN115904317A (en) 2022-11-08 2022-11-08 Method, device, equipment and storage medium for uniformly calling front-end interface and back-end interface

Publications (1)

Publication Number Publication Date
CN115904317A true CN115904317A (en) 2023-04-04

Family

ID=86475425

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211394462.7A Pending CN115904317A (en) 2022-11-08 2022-11-08 Method, device, equipment and storage medium for uniformly calling front-end interface and back-end interface

Country Status (1)

Country Link
CN (1) CN115904317A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116414366A (en) * 2023-04-17 2023-07-11 广东企企通科技有限公司 Middleware interface generation method, device, equipment and medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116414366A (en) * 2023-04-17 2023-07-11 广东企企通科技有限公司 Middleware interface generation method, device, equipment and medium
CN116414366B (en) * 2023-04-17 2024-01-30 广东企企通科技有限公司 Middleware interface generation method, device, equipment and medium

Similar Documents

Publication Publication Date Title
CN111428462B (en) Communication protocol template construction method and terminal equipment
CN109683953B (en) Method and device for processing configuration file based on visual interface
CN109474578B (en) Message checking method, device, computer equipment and storage medium
CN109634841B (en) Electronic device, interface automatic test method and storage medium
CN111290806B (en) Calling method and device of application program interface, computer equipment and storage medium
CN112015396B (en) DSL-based intelligent contract code generation method, device, equipment and storage medium
CN111813701B (en) HTTP-based interface testing method and device, computer equipment and storage medium
CN112558946A (en) Method, device and equipment for generating code and computer readable storage medium
CN114528044B (en) Interface calling method, device, equipment and medium
CN112905459B (en) Service interface testing method and device, electronic equipment and storage medium
KR102226463B1 (en) UI/UX solution providing server linked with process automation program, process automation method using the same, and computer program executing the same
CN108255914B (en) Webpage generation method and application server
CN113127108A (en) Service request processing method and device, storage medium and electronic equipment
CN115904317A (en) Method, device, equipment and storage medium for uniformly calling front-end interface and back-end interface
CN111782207A (en) Method, device and equipment for generating task stream code and storage medium
CN111752820A (en) Pressure testing method of gPC interface, computer equipment and storage medium
CN111324645B (en) Block chain data processing method and device
US10606569B2 (en) Declarative configuration elements
CN114710297B (en) Block chain evidence storing method, device and equipment based on aggregated signature and storage medium
CN114968822A (en) Interface testing method and device, computer equipment and storage medium
CN115481023A (en) Interface data checking method and device, computer equipment and readable storage medium
CN115934537A (en) Interface test tool generation method, device, equipment, medium and product
CN114637672A (en) Automatic data testing method and device, computer equipment and storage medium
CN115022312A (en) Method and device for realizing multiple intelligent contract engines, electronic equipment and storage medium
CN112804066A (en) Method and device for transferring message in cross-link mode based on relay equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination