Method and apparatus for invoking application programming interface
AssigneeTencent Technology (Shenzhen) Company Limited
InventorXiaoxiao Yu
Life of this patent
Estimating the term…
Abstract
A method and an apparatus for invoking an application programming interface (API) are disclosed. The method includes: loading a prestored JS file to a webpage after loading of the webpage is completed; receiving an invoking request that is sent by the webpage by invoking the JS file; and invoking a corresponding API according to a JS URL. This solves a problem that an encoded URL in each webpage needs to be modified when an encoding rule of a URL in a specified format is changed, which is complicated in operation, wastes time, and is poor in compatibility with clients in different versions.
Claims12
A method for invoking an application programming interface (API), applied to a client, the client comprising a memory, one or more processors, and program instructions that are stored in the memory and are executed by the one or more processors, and the method comprising:
- loading, by the client, a webpage hosted by a webserver;
- loading, by the client, a prestored script language JavaScript (JS) file of the client to the webpage after loading of the webpage is completed, the JS file comprising JS uniform resource locators (URLs) corresponding to a plurality of APIs provided by the client;
- receiving, by the client, an invoking request that is sent by the webpage by invoking the JS file, the invoking request carrying a JS URL corresponding to an API needing to be invoked;
- and
- identifying and invoking, by the client, the corresponding API according to the JS URL in the invoking request, comprising:
- extracting the JS URL embedded within the invoking request according to a specified format, wherein the invoking request includes a call for a function to locate the API needing to be invoked, and the JS URL includes an identification of the API needing to be invoked among the plurality of APIs defined in the JS file;
- obtaining a parameter in the JS URL by parsing, wherein the parameter is used for indicating a local hardware resource of the client on which an operation is to be performed when the API is invoked;
- obtaining a path in the JS URL by parsing, wherein the path is used for locating the API for the to-be-performed operation corresponding to the JS URL;
- and
- invoking the API according to the path to perform the operation directed to the local hardware resource corresponding to the parameter.
An apparatus for invoking an application programming interface (API), applied to a terminal, the terminal comprising:
- one or more processors;
- a memory;
- and
- one or more program modules stored in the memory and executed by the one or more processors, the one or more program modules comprising:
- a file loading module, configured to load a prestored script language JavaScript (JS) file of the client to a webpage hosted by a webserver after loading of the webpage is completed, the JS file comprising JS uniform resource locators (URLs) corresponding to a plurality of APIs provided by the client;
- a request receiving module, configured to receive an invoking request that is sent by the webpage by invoking the JS file, the invoking request carrying a JS URL corresponding to an API needing to be invoked;
- and
- an API invoking module, configured to identify and invoke the corresponding API according to the JS URL, comprising:
- extracting the JS URL embedded within the invoking request according to a specified format, wherein the invoking request includes a call for a function to locate the API needing to be invoked, and the JS URL includes an identification of the API needing to be invoked among the plurality of APIs defined in the JS file;
- obtaining a parameter in the JS URL by parsing, wherein the parameter is used for indicating a local hardware resource of the client on which an operation is to be performed when the API is invoked;
- obtaining a path in the JS URL by parsing, wherein the path is used for locating the API for the to-be-performed operation corresponding to the JS URL;
- and
- invoking the API according to the path to perform the operation directed to the local hardware resource corresponding to the parameter.
A non-transitory computer readable storage medium storing computer program instructions that, when being executed by at least one processor of a client, cause the at least one processor to perform:
- loading a webpage hosted by a webserver;
- loading a prestored script language JavaScript (JS) file of the client to the webpage after loading of the webpage is completed, the JS file comprising JS uniform resource locators (URLs) corresponding to a plurality of APIs provided by the client;
- receiving an invoking request that is sent by the webpage by invoking the JS file, the invoking request carrying a JS URL corresponding to an API needing to be invoked;
- and
- identifying and invoking the corresponding API according to the JS URL in the invoking request, comprising:
- extracting the JS URL embedded within the invoking request according to a specified format, wherein the invoking request includes a call for a function to locate the API needing to be invoked, and the JS URL includes an identification of the API needing to be invoked among the plurality of APIs defined in the JS file;
- obtaining a parameter in the JS URL by parsing, wherein the parameter is used for indicating a local hardware resource of the client on which an operation is to be performed when the API is invoked;
- obtaining a path in the JS URL by parsing, wherein the path is used for locating the API for the to-be-performed operation corresponding to the JS URL;
- and
- invoking the API according to the path to perform the operation directed to the local hardware resource corresponding to the parameter.
Dependencies are inferred from the claim text.