Aug 19

 Invoking Web App APIs in Mobile Apps

To access the APIs of WaveMaker Web App (say Project1) into Hybrid Mobile App (say, Project2), you will need to import the services in the form of REST services.

The API’s in Project1 can be of two types:

  • Authenticated: In this case, you will need to either use HTTP Authentication while importing the service or you could use the authorization token as the Header.
  • No authentication: In this case, you can directly import the web API into the project2 as a REST API.

Accessing unAuthenticated Services

  1. In the web app Project1:
    (As an example, we will look at accessing the sample database services i.e hrdb’s services)

    • From the API Designer navigate to the Database Service to access the API’s and from the Test tab copy the Request URL
  2. Open the mobile app, Project2:
    • Using Web Service Integration, import Rest service
    • Provide the above URL as Service URL.
    • Click on Test and Import the web service.

    Note: You will need to deploy your application(Project1) to access its services in Project2.

Accessing Authenticated Services

In the case of Authenticated Web App, you will need to use either HTTP Authentication while importing the service or pass the Authorization token in the Header.

We recommend you generate an authorization token at the initial load of the application (for instance, from the onPageReady event of the landing page of the application or from the onSuccess event of the loginAction, in the case security is enabled for Project2). You can then use the authorization token to access the other authenticated services of Project1.

To import the Web API’s in Project2, you will need to use the Request URL for the API’s calls of Project1. You will be able to access the API’s for the services in the Project1 through the API Designer.

You will need to use HTTP Authentication initially while importing the token API to generate the access token. This access token will then be used to access the remaining authenticated services.

Step 1: Obtain the Auth Token

  1. In the Web App, Project1:
    • From the API Designer, navigate to the Security Service to access the authenticated API’s
    • Locate the Get Token API, and copy the Description Request URL from the Test tab of the API.
  2. Open Mobile App, Project2:
    • Using Web Service Integration, import REST Service
    • Provide the above URL as Service URL.
    • Set HTTP Authentication to Basic and provide the test User Name and Password.
    • Test the connection.
    • From the Response tab, locate and make a note of the wm_auth_token.
    • Import the service.
  3. Variable for Auth Token
    • Access variable dialog and click the New Variable button to create a Model Variable
    • Enter wm_auth_token from the previous step as the dataValue
  4. After the token is generated and stored, you can access the services of Project1 using that token.

Step 2: Accessing Authenticated Services

  1. In the Project1:
    (As an example, we will look at accessing the sample database services i.e HRDB’s services.)

    • From API Designer navigate to the Database Service to access the authenticated API’s
    • from the Test tab copy the Request URL
  2. Open Mobile app, Project2:
    • Import REST Service
    • Provide the above URL
    • In the HEADERS tab provide the Name as “wm_auth_token” and Test Value as the token generated above.
    • Click on Test and Import the web service.

Note: You will need to deploy your application(Project1) to access its services in Project2.

 
We use cookies to provide you with a better experience. By using our website you agree to the use of cookies as described in our Privacy Policy.