WPRM Quick Launch with Example: currency exchange widget

WPRM aka WP RESTful APIs Manager is multi-purpose and can be generally used. It enables you to manage RESTful APIs data – whether it’s live currency exchange, weather forecasting data, google services data, or any other RESTful API – starting from establishing a connection to customizing templates for the results. Here is an example that puts WPRM in action.

Get WPRM Plugin


In this example, we will return a currency exchange table against US dollar using Currency Layer API. Please, make sure that WP Restful Manager Plugin installed and active.

  1. Establishing Connection:
    If you checked the API’s documentation, you will find that to make a request to the service server you have to use a URL which have 2 parts: base url (http://apilayer.net/api/live) and parameters (access_key=YOUR_ACCESS_KEY& currencies=AUD,EUR,GBP,EGP). The first part is static and the second is dynamic in most cases which means that you can change the results if you changed the parameters’ values.
    To establish a connection you need to know 3 thing about your API:

    • Its base url.
    • the results (response) format [Json, XML, etc ..].
    • The parameters Keys: the name of the parameters like access_key & currencies.
    • If your API are authorized with Email and password, so you can check the option of authorized connection and add username and password.
    • If you have any header extra data (sometimes api documentation need you to add authorization key in the header instead of the parameters), add as many as you like in the ‘Extra header data’ section.

    Once you know that, go to Restful Manager > Connection, add a new connection, give it a relevant name(you will need it soon)  and add the data as in the following GIF then click Save.
    Note: You can get access key to the API by signing up for a free plan.

    Click to show full image with clear text

    Authorization section
    Authorization section
  2. Create request and Connection Settings:
    Next, we need to assign those parameters to suitable data so that the web service can query it and return the required data response. In our example and for simplicity, we’ll only add one parameter value which is the access_key.
    Now, go to Restful Manager > Requests, add a new request. and give it a name, then select the connection name that you have just created. When the parameters show up, populate the parameter values as you see in the following GIF.
    As you can see, there are a lot of options in Parameter values setting, most of them are to set the dynamic data retrieval which is one of the features that makes this plugin powerful(we will discuss it more in other tutorial).
    Here we’ve chosen ‘fixed value’ since the access key is not dynamic.
    Once you populated those fields, click save.

    Click to show full
    Click to show full image with clear text
  3. Request’s Display Settings:
    After you save your values, you will find new sections are generated in the request page. One of them is ‘Display Settings’ which responsible for what you want to do with the response results:

    • Display Vs. Save then Display: WPRM give a chance to save selected items from the results in database or just display it in runtime. In this example, we will just choose ‘Display Only’ (‘runtime request’ in old versions) to only display the results.
    •  Where to display results: decide where to show the results template by selecting post type and then before or after content or you can just use a shortcode to add it wherever you like. Also, . We will use shortcode so we can add it as a widget.
    • Showing repeatable results: select where or not to loop through results. This used only when you have a group of results that share the same group of parameter keys(will discussed in other example).
    • Start Checking dummy data: add all values in this section with full fixed(no dynamic work is here) dummy(but correct) data then click ‘check request’ once you see results check only the data that you want it to show up in your app or widget.

      Click to show full
      Click to show full image with clear text
  4. Templating Results:
    Now every thing is ready except how the results will look like!! so here comes the last section, ‘Template Settings’. You will find in it 2 parts:

    • Header or non-repeatable Template: this is the template that we’ll use. you can add text inline style and html to template you results. The links below the editor is a shorthand to help you copy and paste to the editor:
      • the results keys
      • Functional helpers like: if/ifExists/section
    • Repeatable template: if you have a repeatable data you will setup this template exactly as the above to be in for each repeated item at a time.
      Click to show full
      Click to show full image with clear text

      Save the changes once you finish.

To see the output, we’ll copy  and paste the shortcode from the display section in any text widget in your theme.

The orange arrow refers to the output. Live currency exchange values.
The orange arrow refers to the output. Live currency exchange values.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s