=========================================== REST API Test =========================================== In this sample we will write a simplistic web page that tries calling a REST API then displays the response. - We will test with the :ref:`GET_advancedSetting/category/(tenant_id)` API. - We will use JQuery ajax to call the API. - We will display the response in the browser's JavaScript Console. Folder preparation ------------------ #. Create a folder named "ui\_react\_examples" in our web server root folder. A web server is not required for our tutorials. In case of none, just create the "ui\_react\_examples" folder anywhere available. #. Inside it, create a folder named "vendor". This is where we will put the JavaScript library files. #. If using a web server, check the permissions to make sure that it can read the files inside these two folders. API Access Token preparation ---------------------------- API calls need an access token to verify that the client has logged in the system. This access token is returned in the login API result. #. Open Izenda login page in browser. #. Open the browser developer tool (by pressing F12 on most browsers). #. Login to Izenda. #. Switch to Network tab in the developer tool. #. Find the login API response and copy the content of the token field. .. figure:: /_static/images/API_login_token.png :width: 596px Login API Response with Token How to use JQuery library ------------------------- The JQuery library is packaged into a single .js file, with two versions: - Production, which has been minified and compressed. The filename for production version ends with ``.min.js``. - Development, which contains uncompressed and readable code. We will use the development version for debugging purpose. There are also two ways to use the library: - Include it from a content delivery network such as Google or Microsoft. * The link for Google hosted library: |br| ``https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js`` * The link for Microsoft hosted library: |br| ``http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.2.min.js`` - Download it and put into a local folder on our web server, then include the local file in our web page. We will use a local file for instructional purpose: #. Go to http://jquery.com/download/ and download the uncompressed, development version (jquery-1.12.2.js). #. Put it into the "ui\_react\_examples/vendor" folder. Boilerplate HTML page --------------------- #. In "ui\_react\_examples" folder, create a blank text file and name it "REST API Test.html". #. Edit the file with a text editor such as Notepad or Notepad++ and paste the following boilerplate HTML code: .. code-block:: html
For production web site, we will replace ``vendor/jquery-1.12.2.js`` with the link for Google or Microsoft hosted, minified and compressed library. .. _Code_sample_for_calling_REST_API: Code sample for calling REST API -------------------------------- Edit the "REST API Test.html" file to replace ``// TODO`` with our JQuery ajax call: .. code-block:: javascript $.ajax({ headers: { access_token:"