CN112000313A - Request response method, device, equipment and storage medium - Google Patents

Request response method, device, equipment and storage medium Download PDF

Info

Publication number
CN112000313A
CN112000313A CN202010766582.XA CN202010766582A CN112000313A CN 112000313 A CN112000313 A CN 112000313A CN 202010766582 A CN202010766582 A CN 202010766582A CN 112000313 A CN112000313 A CN 112000313A
Authority
CN
China
Prior art keywords
target
request
target class
name
function
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
CN202010766582.XA
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.)
Beijing Dajia Internet Information Technology Co Ltd
Original Assignee
Beijing Dajia Internet Information 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 Beijing Dajia Internet Information Technology Co Ltd filed Critical Beijing Dajia Internet Information Technology Co Ltd
Priority to CN202010766582.XA priority Critical patent/CN112000313A/en
Publication of CN112000313A publication Critical patent/CN112000313A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • G06F8/24Object-oriented
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The disclosure relates to a request response method, a request response device, equipment and a storage medium. The request response method comprises the following steps: responding to a request sent by a client, analyzing the request to obtain an analysis result, wherein the analysis result comprises a first routing character string and a second routing character string; acquiring a target class corresponding to the first routing character string, wherein the target class comprises at least one member function; creating a target class object corresponding to the target class; and calling a target member function in the target class through the target class object to obtain a response result of the request, wherein the target member function is a member function corresponding to the second routing character string. By adopting the request response method, the request response device, the request response equipment and the storage medium, the reusability and the development efficiency of codes can be improved.

Description

Request response method, device, equipment and storage medium
Technical Field
The present disclosure relates to the field of communications technologies, and in particular, to a request response method, apparatus, device, and storage medium.
Background
Currently, when a user browses a website, the user may send a request for accessing a website page to a server, so that the server may map to a specified file based on interface information included in the request, and execute a function in the specified file to return corresponding page content to the user.
In the related art, different functions called by a request are stored in different files of a server, developers need to manually configure interface information for each file, and manually configure mapping modes between the interface information and the files, so that the reusability and the development efficiency of codes are reduced, and the development cost of the codes is increased.
Disclosure of Invention
The present disclosure provides a request response method, apparatus, device and storage medium, to at least solve the problems of low code reuse and development efficiency in the related art. The technical scheme of the disclosure is as follows:
according to a first aspect of the embodiments of the present disclosure, there is provided a request response method, including: responding to a received request sent by a client, and analyzing the request to obtain an analysis result; the analysis result comprises a first routing character string and a second routing character string; acquiring a target class corresponding to the first routing character string; wherein the target class comprises at least one member function; creating a target class object corresponding to the target class; calling a target member function in the target class through the target class object to obtain a response result of the request; and the target member function is a member function corresponding to the second routing character string.
In one embodiment, the first routing string includes a target class name, and the target class is a class whose name includes the target class name.
In one embodiment, obtaining the target class corresponding to the first routing character string includes: acquiring a target file corresponding to the target class name; wherein, the target file comprises a target class; and extracting the target class from the target file.
In one embodiment, parsing the request to obtain a parsing result includes: acquiring a Uniform Resource Locator (URL) in the request; and extracting the target class name from the URL according to a first preset extraction mode.
In one embodiment, the second routing string includes an objective function name, and the objective member function is a member function whose name includes the objective function name.
In one embodiment, parsing the request to obtain a parsing result includes: acquiring a URL in the request; extracting a target variable name from the URL according to a second preset extraction mode; and taking the target variable name as the target function name.
In one embodiment, after obtaining the response result of the request, the method further includes: determining the function type of the target member function according to the second routing character string; and sending a response result to the client under the condition that the function type is the target type.
In one embodiment, after determining the function type of the target member function according to the second routing string, the method further comprises: in the case where the function type is not the target type, the response result is intercepted.
According to a second aspect of the embodiments of the present disclosure, there is provided a request response apparatus including: the request analysis unit is configured to respond to the received request sent by the client and analyze the request to obtain an analysis result; the analysis result comprises a first routing character string and a second routing character string; the function acquisition unit is configured to execute acquisition of a target class corresponding to the first routing character string; wherein the target class comprises at least one member function; the object creating unit is configured to execute the creation of a target class object corresponding to a target class; the function calling unit is configured to execute the target member function in the target class by the target class object and call the target member function in the target class to obtain a response result of the request; and the target member function is a member function corresponding to the second routing character string.
In one embodiment, the first routing string includes a target class name, and the target class is a class whose name includes the target class name.
In one embodiment, the function obtaining unit includes: the first processing unit is configured to execute acquisition of a target file corresponding to a target class name; wherein, the target file comprises a target class; a second processing unit configured to perform extracting the target class from the target file.
In one embodiment, the request parsing unit includes: a third processing unit configured to execute a uniform resource locator URL in the acquisition request; and the fourth processing unit is configured to extract the target class name from the URL according to the first preset extraction mode.
In one embodiment, the second routing string includes an objective function name, and the objective member function is a member function whose name includes the objective function name.
In one embodiment, the request parsing unit includes: a third processing unit configured to execute the URL in the acquisition request; the fifth processing unit is configured to extract the target variable name from the URL according to a second preset extraction mode; a sixth processing unit configured to execute the target variable name as the target function name.
In one embodiment, the apparatus further comprises: a type determination unit configured to perform determining a function type of the target member function according to the second routing string; and the result sending unit is configured to send the response result to the client when the function type is the target type.
In one embodiment, the apparatus further comprises: a result intercepting unit configured to intercept the response result in case the function type is not the target type.
According to a third aspect of the embodiments of the present disclosure, there is provided a server, including: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the request response method as described in the first aspect.
According to a fourth aspect of embodiments of the present disclosure, there is provided a storage medium, wherein instructions of the storage medium, when executed by a processor of a server, enable the server to perform the request response method according to the first aspect.
According to a fifth aspect of embodiments of the present disclosure, there is provided a computer program product, wherein instructions of the computer program product, when executed by a processor of a server, enable the server to perform the request response method according to the first aspect.
The technical scheme provided by the embodiment of the disclosure at least brings the following beneficial effects:
in the embodiment of the disclosure, the target class can be obtained based on the first routing character string carried in the request, a new class object is created by using the target class, and then, the target member function in the target class corresponding to the second routing character string carried in the request is called through the created target class object to obtain the response result of the request, so as to realize the response to the request sent by the client, without configuring interface information for files of different functions or configuring a mapping mode for the interface information and the files, thereby improving the reusability and the development efficiency of codes and reducing the development cost.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure and are not to be construed as limiting the disclosure.
FIG. 1 is an architectural diagram illustrating a request response in accordance with an exemplary embodiment.
FIG. 2 is a diagram illustrating an application scenario for a request response in accordance with an illustrative embodiment.
Fig. 3 is a flow chart illustrating a request response method in accordance with an example embodiment.
FIG. 4 is a flow diagram illustrating a method for querying a target class in accordance with an exemplary embodiment.
FIG. 5 is a flow chart illustrating another request response method in accordance with an exemplary embodiment.
FIG. 6 is a flow diagram illustrating a request response process in accordance with an exemplary embodiment.
Fig. 7 is a block diagram illustrating a request response device in accordance with an example embodiment.
FIG. 8 is a block diagram illustrating a server in accordance with an exemplary embodiment.
FIG. 9 is a block diagram illustrating an apparatus for requesting a response in accordance with an example embodiment.
Detailed Description
In order to make the technical solutions of the present disclosure better understood by those of ordinary skill in the art, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the above-described drawings are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the disclosure described herein are capable of operation in sequences other than those illustrated or otherwise described herein. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present disclosure, as detailed in the appended claims.
The request response method provided by the present disclosure may be applied to the architectures shown in fig. 1 and fig. 2, and is specifically described in detail with reference to fig. 1 and fig. 2.
FIG. 1 is an architectural diagram illustrating a request response in accordance with an exemplary embodiment.
As shown in fig. 1, the architecture diagram may include at least one electronic device 110 of a client and a server 120 of a server. The server 120 may establish a connection with the electronic device 10 of at least one user through a network Protocol such as hypertext Transfer Protocol (HTTP) and perform information interaction. The electronic device 110 may be a mobile phone, a computer, a tablet device, a fitness device, a personal digital assistant, or other devices with a communication function. The server 120 may be a device having storage and computing functions, such as a cloud server or a server cluster.
Based on the above-mentioned architecture, when the user accesses an application on the electronic device 110, or accesses some specific network platform through the electronic device 110, the electronic device 110 sends a request to the server 120, so that the server 120 can respond to the request to obtain a response result, and return corresponding page content to the user according to the response result.
In order to improve the reusability and development efficiency of the code in the server 120, in the embodiment of the present disclosure, it is not necessary to encapsulate the files and functions stored in the respective servers 120 to configure interface information for each file and each function, and it is also not necessary to configure a mapping manner for each interface information and each file. In particular, in the disclosed embodiments, classes and member functions in the classes may be stored directly in the form of files in the server 120 and need not be packaged. The request sent by the electronic device 110 to the server 120 may carry a first routing string for querying the target class in the file and a second routing string for calling the target member function. After receiving the request sent by the electronic device 110, the server 120 may first parse the received request to obtain a first routing character string and a second routing character string carried in the request, then may obtain a target class corresponding to the first routing character string, and temporarily create a target class object corresponding to the target class, and then directly call a target member function corresponding to the second routing character string in the target class through the target class object to obtain a response result of the request.
Taking the server 120 as a Node language-based server as an example, the server 120 may be a Node type server written in a Node language. Specifically, when the server 120 is built, a service object master file with a route distribution function may be created first, then a service response object for responding to data to a client is created based on the service object master file, and the service response object is modularly exported, so as to obtain a service response object interface that can be invoked. After the server 120 receives the request sent by the electronic device 110, the service response object interface may be called to execute a service response object, so that the service response object may parse the received request to obtain a first routing character string and a second routing character string carried in the request, then may obtain a target class corresponding to the first routing character string, and temporarily create a target class object corresponding to the target class, and then directly call a target member function corresponding to the second routing character string in the target class through the target class object to obtain a response result of the request.
In this way, the server 120 can directly search the class corresponding to the request without configuring interface information for files of different functions or configuring a mapping mode for the interface information and the files, and create the class object corresponding to the class, so as to call the member function corresponding to the request through the class object, thereby realizing the response to the request sent by the client, improving the reusability and the development efficiency of the code, and reducing the development cost.
To better illustrate the architecture of the request response provided by the embodiments of the present disclosure, further description is provided below with respect to fig. 2.
FIG. 2 is a diagram illustrating an application scenario for a request response in accordance with an illustrative embodiment.
In fig. 2, a scenario in which a user logs in to a network platform is shown. As shown in FIG. 2, during the login process, the user may enter an account number such as 123456789 and a password on the electronic device 110 and click the "login" button. After the user clicks the "login" button, the electronic device 110 may send a login request to the server 120 of the network platform, after the server 120 receives the login request, the server may first parse the received login request to obtain a first routing character string and a second routing character string carried in the login request, may then obtain a target class corresponding to the first routing character string, and temporarily create a target class object corresponding to the target class, and then directly call a login authentication function corresponding to the second routing character string in the target class through the target class object to obtain a response result of the login request.
In this way, the server 120 can directly search the class corresponding to the request and create the class object corresponding to the class, so as to call the member function corresponding to the request through the class object, thereby implementing the response to the request sent by the client, improving the reusability and development efficiency of the code, and reducing the development cost.
Further, after the target member function obtains the response result of the login request, the server 120 may determine the function type of the target member function. If the function type is a target type facing the client, a response result may be directly sent to the client to return the corresponding page content to the user, for example, if the response result obtained by executing the target member function is successful in login, the page content corresponding to the successful login may be fed back to the electronic device 110. After receiving the page content corresponding to the successful login, the electronic device 110 may display a login success page. If the function type is not a client-oriented target type, the response result may be directly intercepted to secure the data of the server 120.
In this way, the server 120 may manage and control whether to feed back the response result to the electronic device 110 based on the function type of the member function, so as to improve data security of the server 120, and reduce a risk that the user calls a member function that is not directed to the client to illegally obtain data by requesting.
According to the above architecture and application scenarios, the request response method provided by the embodiment of the present disclosure is described in detail below with reference to fig. 3 to fig. 7, where the request response method may be executed by the server 120 shown in fig. 1 and fig. 2, or may be executed by a functional module in the server 120, which is not limited herein.
Fig. 3 is a flow chart illustrating a request response method in accordance with an example embodiment. As shown in fig. 3, the request response method includes the following steps.
In S310, in response to receiving a request sent by a client, analyzing the request to obtain an analysis result; and the analysis result comprises a first routing character string and a second routing character string.
In some embodiments of the present disclosure, the request sent by the client may be a request for implementing data interaction. The request may include various forms, such as a link, an HTTP web page request or protocol, and the like, without limitation.
In some embodiments, the server may be configured to receive requests sent by all the clients uniformly, and may further determine a response result of the request in response to the received request.
In other embodiments, the server may be further configured to receive a request sent by a part of the clients for which the server is responsible, and further may determine a response result of the request in response to the received request.
In the disclosed embodiment, each request uniquely corresponds to a function that the request uses for execution, i.e., each request can execute only one of different functions such as GET, POST, PUT, or DELETE.
In S310 of some embodiments of the present disclosure, the request data may directly carry the first routing character string and the second routing character string, and at this time, the server may analyze the request data to directly obtain the first routing character string and the second routing character string.
In S310 of other embodiments of the present disclosure, the request data may include a Uniform Resource Locator (URL), and the URL may carry the first routing character string and the second routing character string, at this time, the server may analyze the URL to obtain the first routing character string and the second routing character string, and details on the implementation manner will be described later.
In this disclosure, the first routing string may be a string used for finding a target class corresponding to the request, for example, the first routing string may be a target class name of the target class or a target file name of a target file used for storing the target class.
For example, if the target class name of the target class is Person and the target file name of the target file storing the target class is also Person, the first routing string may be Person. For another example, if the target class name of the target class is Person, the target file name of the target file storing the target class is a, and only the target class is stored in the target file, the first routing string may be a. For another example, if the target class name of the target class is Person, the target file name of the target file storing the target class is a, and a plurality of classes are stored in the target file, the first routing string may be Person.
In this disclosure, the second routing string may be a string used for finding a target member function corresponding to the request, for example, the second routing string may include a target function name of the target member function or a target variable name of a target variable used by the target member function.
In the case where the second routing string is a target variable name of a target variable used by the target member function, the target variable name may be used as the target function name.
For example, if the target function name of the target member function is func, the second routing string may be func. For another example, if the target function name of the target member function is a dynamically defined function name, the second routing string may be the target variable name of the target variable used by the target member function.
In S320, a target class corresponding to the first routing character string is obtained; wherein the target class includes at least one member function.
In S320 of some embodiments of the present disclosure, in a case where the first routing character string is a target class name, if a target file name of a target file storing the target class is different from the target class name, the class name of each class in each file may be traversed to obtain the target class whose class name is the target class name.
In S320 in some other embodiments of the present disclosure, when the first routing character string is a target class name, if the target file name of the target file storing the target class is the same as the target class name and only the target class is stored in the target file, the target file whose file name is the target class name may be directly found, and the target class in the target file is obtained, and this implementation will be described in detail later.
In S330 of some embodiments of the present disclosure, in a case that the first routing character string is a target file name, the target file with the file name as a target class name may be directly found, and the target class in the target file is obtained.
In S330, a target class object corresponding to the target class is created.
In S330 of the embodiment of the present disclosure, the server may perform instantiation processing on the target class to create a target class object corresponding to the target class. In the process of creating the target class object, the constructor in the target class can be automatically executed to obtain the request basic data needed for executing the target member function.
Specifically, the request data may carry request basic data, and the analysis result obtained after analyzing the request may further include request basic information, where the request basic data is used to assign a variable of a member function when the member function in the target class object is called. Constructors in the target class can be automatically executed to obtain request basic data in the analysis result.
With continued reference to fig. 2, 123456789 and the password carried in the login request are the request basic data for assigning values to its variables when invoking the login authentication function.
In S340, a target member function in the target class is called through the target class object to obtain a response result of the request; and the target member function is a member function corresponding to the second routing character string.
In S340 of the embodiment of the present disclosure, a target member function corresponding to the second routing character string may be called through the target class object, and assignment is performed on a target variable in the target member function based on the request basic data, so as to execute the target member function, and obtain a response result of the request.
Therefore, in the embodiment of the present disclosure, the target class can be obtained based on the first routing character string carried in the request, a new class object is created by using the target class, and then, the target member function in the target class corresponding to the second routing character string carried in the request is called through the created target class object to obtain the response result of the request, so as to implement the response to the request sent by the client, without configuring interface information for files of different functions, and without configuring a mapping manner for the interface information and the files, thereby improving the reusability and development efficiency of the code, and reducing the development cost.
In other embodiments of the present disclosure, in order to improve the query efficiency of the target class, the file name of each file for storing classes may be set as the class name of the stored class, and only one class is stored in the file. At this time, the first routing string may include a target class name, and the target class may be a class whose name includes the target class name.
In some embodiments of the present disclosure, to improve request response efficiency, the first routing string may be carried in the URL of the request.
Optionally, S310 may include:
acquiring a URL in the request;
and extracting the target class name from the URL according to a first preset extraction mode.
The first preset extraction mode may be to acquire a character string at a first preset position. The first preset position may be a position agreed in the URL for arranging a character string indicating a class name. Alternatively, for ease of querying, the first preset position may be a first target position relative to a first target symbol, e.g., before the nth symbol "/", N is a positive integer.
Specifically, the server may obtain the URL included in the request, divide the URL, and obtain the character string at the first preset location according to the division result, to obtain the name of the target class carried in the URL.
For example, if the URL included in the request is "http:// Person/login", the URL may be divided, for example, the following part of the URL may be obtained, and since a character string preceding the first symbol "/" is agreed as a character string indicating a class name in the URL, Person may be obtained as the target class name.
FIG. 4 is a flow diagram illustrating a method for querying a target class in accordance with an exemplary embodiment. As shown in fig. 4, S320 includes the following steps.
In S322, a target file corresponding to the target class name is obtained; wherein, the target file comprises the target class.
In S322 of some embodiments of the present disclosure, since the class name and the file name are the same, the server may obtain a file name list containing all files in the server, then query the file name list for a target file name that is the same as the target class name, and obtain a target file corresponding to the target file name based on the queried target file name.
In S324, a target class is extracted from the target file.
In S324 of some embodiments of the present disclosure, the server may directly extract a class function corresponding to the target class from the target file, so as to perform instantiation processing on the extracted class function, and obtain the target class object.
In some embodiments of the present disclosure, the server also needs to establish a file name list before S322. Specifically, the server may first traverse all the stored files for the storage class by a preset suffix to obtain a plurality of file names, where the file names include a file name and a preset suffix. Then, the server may remove a preset suffix in the file name through the regular expression, thereby obtaining the file name in each file name, and finally, the server may arrange the file names in order (e.g., in an initial order) to generate a file name list.
For example, the preset suffix may be ". js", and the file for the storage class may be stored as a routing file in a designated folder, such as a routing folder. The server can traverse all the routing files in the routing folder, acquire file names with the 'js', then remove the 'js' in each file name through the expression to obtain the file name in each file name, finally arrange the file names according to the initial sequence to generate a file name list, each file name in the file name list has a preset mapping relation with one routing file, the server can quickly search a target file name which is the same as the target class name through the file name list, and quickly acquire a target file corresponding to the target file name through the preset mapping relation.
Therefore, the server can traverse all the stored files for the storage class at preset time intervals, automatically detect the change of the routing files, and automatically update the file name list according to the file names of the newly added routing files, so that the accuracy of the query result of the target class is improved.
In still other embodiments of the present disclosure, the second routing string may include an objective function name, and the objective member function may be a member function whose name includes the objective function name.
In some embodiments of the present disclosure, to improve request response efficiency, the second routing string may be carried in the URL of the request.
Optionally, S310 may include:
acquiring a URL in the request;
and extracting the name of the target function from the URL according to a third preset extraction mode.
The third preset extraction mode may be to acquire a character string at a third preset position. The third preset position may be a position agreed in the URL for arranging a character string indicating a function name. Alternatively, for ease of querying, the third preset position may be a third target position relative to a third target symbol, e.g., after the mth symbol "/", M is a positive integer. Wherein the third target symbol may be the same as or different from the first target symbol.
Specifically, the server may obtain the URL included in the request, divide the URL, and obtain the character string at the third preset position according to the division result, to obtain the name of the target function carried in the URL.
For example, if the URL included in the request is "http:// Person/login", the URL may be divided, for example, the following part of the URL may be obtained, and since the character string following the first symbol "/" is agreed as the character string indicating the function name in the URL, login may be obtained as the target function name.
Therefore, the server can take the function name of each member function in each class as an interface for calling the member function, a new interface does not need to be manually defined for the member function, development cost is reduced, and development efficiency and code reusability are improved.
Alternatively, since the target function names of some target member functions are dynamically defined function names, in order to improve the reusability of the code, the target variable names may be taken as the target function names, i.e., the second routing string may include the target variable names.
In some embodiments of the present disclosure, to improve request response efficiency, the second routing string may be carried in the URL of the request.
Optionally, S310 may include:
acquiring a URL in the request;
extracting a target variable name from the URL according to a second preset extraction mode;
and taking the target variable name as the target function name.
The second preset extraction mode may be to acquire a character string at a second preset position. The second preset position may be a position for arranging a character string indicating a variable name, which is agreed in the URL. Optionally, for convenience of querying, the second preset position may be a second target position relative to a second target symbol, e.g., after the kth symbol ": K is a positive integer. Wherein the second target symbol may be the same as or different from the first target symbol.
Specifically, the server may obtain the URL included in the request, divide the URL, obtain the character string at the second preset location according to the division result, obtain the target variable name carried in the URL, and further use the target variable name as the target function name.
For example, if the URL included in the request is "http:// Person/login: name", the URL may be divided, for example, to obtain the later part of the URL, since the character string following the first symbol ": is a character string indicating the name of the variable, is agreed in the URL. Therefore, the name can be acquired as the target variable name.
Therefore, the server can use the variable names used by the member functions in the classes as the interfaces for calling the member functions, and does not need to manually define new interfaces for the member functions, so that the development cost is reduced, and the development efficiency and the code reusability are improved.
In some embodiments of the present disclosure, since the function name is used as an interface of a member function, a client may call any member function in a server at will, and in order to protect data security of the server, an embodiment of the present disclosure further provides a request response method.
FIG. 5 is a flow chart illustrating another request response method in accordance with an exemplary embodiment. As shown in fig. 5, the request response method includes the following steps.
In S510, in response to receiving a request sent by a client, analyzing the request to obtain an analysis result; and the analysis result comprises a first routing character string and a second routing character string.
In S520, a target class corresponding to the first routing character string is obtained; wherein the target class includes at least one member function.
In S530, a target class object corresponding to the target class is created.
In S540, a target member function in the target class is called through the target class object to obtain a response result of the request; and the target member function is a member function corresponding to the second routing character string.
S510-S540 are the same as S310-S340 shown in fig. 3, and are not described herein.
In S550, a function type of the target member function is determined according to the second routing string.
In S550 of some embodiments of the present disclosure, in a case that the second routing string is a name of the target function, the server may determine the function type of the target member function according to a corresponding relationship between the name of the target function and the function type.
In S550 of other embodiments of the present disclosure, when the second routing string is the target variable name, the server may determine the function type of the target member function according to a corresponding relationship between the target variable name and the function type.
In S560, it is determined whether the function type is a target type;
in the embodiment of the present disclosure, the target type is a function type oriented to the client, and specifically, the response result of the member function corresponding to the target type is data that can be disclosed to the user.
In S560 of some embodiments of the present disclosure, the server may query the function type of the target member function in the function type list corresponding to the target type, if the query is received, the function type of the target member function is the target type, otherwise, the function type of the target member function is not the target type.
In S570, in the case where the function type is the target type, the response result is sent to the client.
In S570 of some embodiments of the present disclosure, when the function type is the target type, taking the response result as the return value as an example, the server may directly feed back the page content corresponding to the return value to the client.
In S580, in the case where the function type is not the target type, the response result is intercepted.
In S580 of some embodiments of the present disclosure, in a case that the function type is not the target type, taking the response result as the return value as an example, the server may directly intercept the return value, so as to avoid data leakage that cannot be disclosed to the user, thereby protecting data security of the server.
Therefore, in the embodiment of the disclosure, the return value of the function which can be disclosed to the client can be directly returned to the client, and the return value of the function which cannot be disclosed to the client is automatically intercepted, so that not only is an interface logic for feeding back the return value to the client not required to be separately processed by a developer, but also the data security of the server can be improved.
In the following, taking the Node type server as an example, the request response method provided by the present disclosure is further described in detail.
FIG. 6 is a flow diagram illustrating a request response process in accordance with an exemplary embodiment. As shown in fig. 6, the request response process includes the following steps.
In S610, a request sent by the client is received.
In S620, the URL in the request is parsed, the URL is divided, and the target class name and the target variable name are obtained according to the division result.
In S630, the target class name and the target variable name are concatenated using preset symbols to obtain the routing data, for example, concatenated using symbols such as colon and comma.
In S640, the service response object is executed by the use module, the route data is used as an execution parameter of the service response object, the service response object obtains a target class based on a target class name in the route data, then a target class object corresponding to the target class is created, a target member function in the target class is called based on a target variable name in the route data to obtain a return value of the target member function, and the return value is returned by a return statement.
In S650, according to the corresponding relationship between the target variable name and the function type, determining the function type of the target member function, and determining whether the target member function is the target type, if so, performing S660, and if not, performing S670.
In S660, the return value is fed back to the client.
In S670, a return value is intercepted.
Therefore, in the embodiment of the disclosure, an interface does not need to be configured for a class and a member function in the class separately, a class name can be directly used as an interface of the class, a function name or a variable name used by the member function is used as an interface of the member function, automatic routing and automatic matching of a request are realized, and by defining a function type capable of feeding back a return value to a client, data security of a server is protected, not only is linked call of multiple interfaces realized, but also data security of the server can be improved.
Fig. 7 is a block diagram illustrating a request response device in accordance with an example embodiment. Referring to fig. 7, the request responding apparatus 700 may include a request parsing unit 710, a function obtaining unit 720, an object creating unit 730, and a function calling unit 740.
The request parsing unit 710 may be configured to, in response to receiving a request sent by a client, parse the request to obtain a parsing result; and the analysis result comprises a first routing character string and a second routing character string.
The function obtaining unit 720 may be configured to perform obtaining a target class corresponding to the first routing string; wherein the target class includes at least one member function.
The object creating unit 730 may be configured to perform creating a target class object corresponding to the target class.
The function calling unit 740 may be configured to execute calling a target member function in the target class through the target class object, and obtain a response result of the request; and the target member function is a member function corresponding to the second routing character string.
In the embodiment of the present disclosure, the request responding apparatus 700 can obtain the target class based on the first routing string carried in the request, create a new class object by using the target class, and then call the target member function in the target class corresponding to the second routing string carried in the request through the created target class object to obtain the response result of the request, so as to implement the response to the request sent by the client, without configuring interface information for files of different functions, or configuring a mapping manner for the interface information and the files, thereby improving the reusability and development efficiency of the code, and reducing the development cost.
In some embodiments of the present disclosure, the first routing string may include a target class name, and the target class may be a class whose name includes the target class name.
In some embodiments of the present disclosure, the function obtaining unit 720 may include a first processing unit and a second processing unit.
The first processing unit may be configured to execute acquiring a target file corresponding to a target class name; wherein, the target file comprises the target class.
The second processing unit may be configured to perform extracting the target class from the target file.
In some embodiments of the present disclosure, the request parsing unit 710 may include a third processing unit and a fourth processing unit.
The third processing unit may be configured to execute a uniform resource locator, URL, in the fetch request.
The fourth processing unit may be configured to perform extracting the target class name in the URL according to a first preset extraction manner.
In some embodiments of the present disclosure, the second routing string may include an objective function name, and the objective member function may be a member function whose name includes the objective function name.
In some embodiments of the present disclosure, the request parsing unit 710 may include a third processing unit, a fifth processing unit, and a sixth processing unit.
The third processing unit may be configured to execute the URL in the fetch request;
the fifth processing unit may be configured to perform extracting the target variable name in the URL in a second preset extraction manner.
The sixth processing unit may be configured to perform naming of the target variable as the target function name.
In some embodiments of the present disclosure, the request responding apparatus 700 may further include a type determining unit and a result transmitting unit.
The type determining unit may be configured to perform determining a function type of the target member function based on the second routing string.
The result transmitting unit may be configured to transmit the response result to the client in a case where the function type is the target type.
In some embodiments of the present disclosure, the request responding apparatus 700 may further include a result intercepting unit.
The result intercepting unit is configured to intercept the response result if the function type is not the target type.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
FIG. 8 is a block diagram illustrating a server in accordance with an exemplary embodiment.
As shown in fig. 8, the server may refer to the server 120 shown in fig. 1 and 2 in an embodiment of the present disclosure. The server may include a processor 810, a communication interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other via the communication bus 840.
The memory 830 is used for storing instructions executable by the processor 810.
The processor 810, when executing the instructions stored in the memory 830, implements the following steps:
responding to a received request sent by a client, and analyzing the request to obtain an analysis result; the analysis result comprises a first routing character string and a second routing character string;
acquiring a target class corresponding to the first routing character string; wherein the target class comprises at least one member function;
creating a target class object corresponding to the target class;
calling a target member function in the target class through the target class object to obtain a response result of the request; and the target member function is a member function corresponding to the second routing character string.
In the embodiment of the disclosure, the target class can be obtained based on the first routing character string carried in the request, a new class object is created by using the target class, and then, the target member function in the target class corresponding to the second routing character string carried in the request is called through the created target class object to obtain the response result of the request, so as to realize the response to the request sent by the client, without configuring interface information for files of different functions or configuring a mapping mode for the interface information and the files, thereby improving the reusability and the development efficiency of codes and reducing the development cost.
FIG. 9 is a block diagram illustrating an apparatus for requesting a response in accordance with an example embodiment. For example, the device 900 may be provided as a server.
Referring to fig. 9, device 900 includes a processing component 922, which further includes one or more processors, and memory resources, represented by memory 932, for storing instructions, such as applications, that are executable by processing component 922. The application programs stored in memory 932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 922 is configured to execute instructions to perform a request response method as described in any of the embodiments above.
The device 900 may also include a power component 926 configured to perform power management of the device 900, a wired or wireless network interface 950 configured to connect the device 900 to a network, and an input/output (I/O) interface 958. The device 900 may operate based on an operating system stored in the memory 932, such as Windows Server, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, or the like.
In some embodiments of the present disclosure, there is also provided a storage medium, wherein instructions when executed by a processor of a server enable the server to perform the request response method of any of the above embodiments.
Alternatively, the storage medium may be a non-transitory computer readable storage medium, which may be, for example, a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
In some embodiments of the present disclosure, there is also provided a computer program product, wherein instructions of the computer program product, when executed by a processor of a server, enable the server to perform the request response method of any of the above embodiments.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. A request response method, comprising:
responding to a received request sent by a client, and analyzing the request to obtain an analysis result; the analysis result comprises a first routing character string and a second routing character string;
acquiring a target class corresponding to the first routing character string; wherein the target class comprises at least one member function;
creating a target class object corresponding to the target class;
calling a target member function in the target class through the target class object to obtain a response result of the request; and the target member function is a member function corresponding to the second routing character string.
2. The method of claim 1, wherein the first routing string comprises a target class name, and wherein the target class is a class whose name comprises the target class name.
3. The method according to claim 2, wherein the obtaining the target class corresponding to the first routing string includes:
acquiring a target file corresponding to the target class name; wherein the target file comprises the target class;
and extracting the target class from the target file.
4. The method of claim 2, wherein parsing the request to obtain a parsed result comprises:
acquiring a Uniform Resource Locator (URL) in the request;
and extracting the target class name from the URL according to a first preset extraction mode.
5. The method of claim 1, wherein the second routing string comprises an objective function name, and wherein the objective member function is a member function whose name comprises the objective function name.
6. The method of claim 5, wherein parsing the request to obtain a parsed result comprises:
acquiring the URL in the request;
extracting a target variable name from the URL according to a second preset extraction mode;
and taking the target variable name as the target function name.
7. The method of claim 1, wherein after obtaining the response result of the request, the method further comprises:
determining the function type of the target member function according to the second routing character string;
and sending the response result to the client under the condition that the function type is a target type.
8. A request response device, comprising:
the request analysis unit is configured to respond to a received request sent by a client and analyze the request to obtain an analysis result; the analysis result comprises a first routing character string and a second routing character string;
a function obtaining unit configured to perform obtaining of a target class corresponding to the first routing character string; wherein the target class comprises at least one member function;
the object creating unit is configured to create a target class object corresponding to the target class;
the function calling unit is configured to execute calling a target member function in the target class through the target class object to obtain a response result of the request; and the target member function is a member function corresponding to the second routing character string.
9. A server, comprising:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the request response method of any of claims 1 to 7.
10. A storage medium, wherein instructions in the storage medium, when executed by a processor of a server, enable the server to perform the request response method of any one of claims 1 to 7.
CN202010766582.XA 2020-08-03 2020-08-03 Request response method, device, equipment and storage medium Pending CN112000313A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010766582.XA CN112000313A (en) 2020-08-03 2020-08-03 Request response method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010766582.XA CN112000313A (en) 2020-08-03 2020-08-03 Request response method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN112000313A true CN112000313A (en) 2020-11-27

Family

ID=73463445

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010766582.XA Pending CN112000313A (en) 2020-08-03 2020-08-03 Request response method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112000313A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114637497A (en) * 2022-05-19 2022-06-17 佛山众陶联供应链服务有限公司 Method and system for interface serialization response field

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2015018243A1 (en) * 2013-08-06 2015-02-12 飞天诚信科技股份有限公司 Ios device based webpage blocking method and device
CN106022122A (en) * 2016-05-31 2016-10-12 北京金山安全软件有限公司 Information processing method and device
CN107209666A (en) * 2014-12-12 2017-09-26 微软技术许可有限责任公司 Computer system
CN107809383A (en) * 2016-09-08 2018-03-16 腾讯科技(深圳)有限公司 A kind of map paths method and device based on MVC
CN109445968A (en) * 2018-11-09 2019-03-08 金瓜子科技发展(北京)有限公司 Service request processing method, device, equipment and the storage medium of different agreement
CN110457132A (en) * 2019-08-01 2019-11-15 武汉斗鱼鱼乐网络科技有限公司 A kind of creation method of functional object, device and terminal device
CN110674427A (en) * 2019-09-20 2020-01-10 北京达佳互联信息技术有限公司 Method, device, equipment and storage medium for responding to webpage access request
CN111242768A (en) * 2019-12-31 2020-06-05 航天信息股份有限公司 Credit card information security obtaining method, device and system

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2015018243A1 (en) * 2013-08-06 2015-02-12 飞天诚信科技股份有限公司 Ios device based webpage blocking method and device
CN107209666A (en) * 2014-12-12 2017-09-26 微软技术许可有限责任公司 Computer system
CN106022122A (en) * 2016-05-31 2016-10-12 北京金山安全软件有限公司 Information processing method and device
CN107809383A (en) * 2016-09-08 2018-03-16 腾讯科技(深圳)有限公司 A kind of map paths method and device based on MVC
CN109445968A (en) * 2018-11-09 2019-03-08 金瓜子科技发展(北京)有限公司 Service request processing method, device, equipment and the storage medium of different agreement
CN110457132A (en) * 2019-08-01 2019-11-15 武汉斗鱼鱼乐网络科技有限公司 A kind of creation method of functional object, device and terminal device
CN110674427A (en) * 2019-09-20 2020-01-10 北京达佳互联信息技术有限公司 Method, device, equipment and storage medium for responding to webpage access request
CN111242768A (en) * 2019-12-31 2020-06-05 航天信息股份有限公司 Credit card information security obtaining method, device and system

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114637497A (en) * 2022-05-19 2022-06-17 佛山众陶联供应链服务有限公司 Method and system for interface serialization response field

Similar Documents

Publication Publication Date Title
EP3229148B1 (en) Website access method and device, and website system
EP2129148B1 (en) Content distribution system
CN110334297B (en) Terminal page loading method, terminal, server and storage medium
CN110365724B (en) Task processing method and device and electronic equipment
CN107463453B (en) Method, device, equipment and storage medium for communication between different applications of same terminal
CN110399578B (en) Page access method and device
CN111708702A (en) Simulation test method, client, server, system and readable storage medium
WO2015021873A1 (en) Method, platform server, and system of data pushing
CN110598135A (en) Network request processing method and device, computer readable medium and electronic equipment
CN110928545B (en) Component distribution method, development method and device of single-page application and storage medium
EP3393104B1 (en) Requests and responses processing methods, terminal, server and computer-readable media
CN113779422B (en) Method and device for realizing relationship chain label, electronic equipment and storage medium
CN109981546B (en) Method and device for acquiring remote call relation between application modules
CN111488286B (en) Method and device for independently developing Android modules
CN103544209A (en) Method and system for web page access
CN112000313A (en) Request response method, device, equipment and storage medium
CN111241504B (en) Identity verification method, device, electronic equipment and storage medium
CN112306591B (en) Remote debugging method and device based on page
CN116668520A (en) Gateway-based service arrangement method, system, equipment and storage medium
CN111756916A (en) Application processing method and device, electronic equipment and computer storage medium
CN104980511A (en) Game data access method, game data access system and game web server
CN113220296B (en) Android system interaction method and device
CN111581578B (en) Interface request processing method and device
CN111400623B (en) Method and device for searching information
CN114186156A (en) Access method, device, medium and equipment for sub-application

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