Using a Query Parameter in a Live Feed



Introduction


You can add a parameter when requesting data from a Live Feed

This permits you to make identical calls to your web service, and change the parameters to receive different responses from the server.

To define query parameters that will be sent with a remote data source, you need to use the Query Parameters field found on the edit page for a remote data source.

You can also create RESTful calls, directly from your app: Tutorial on how make RESTful calls.

 In this Tutorial we use a Tutorial app to illustrate how it works.

We will see that feed set up with Query parameters are filtered using: Define a Data Source Filter action.


Install the tutorial app


Go to your Dashboard, select 'Tutorial' and then choose 'Remote Query Parameter' App -
Or click here to immediately install the Tutorial App in your Workspace.

 


Overview of the App


The Tutorial app uses a BBC public RSS feed working with a query parameter that determines which region the entertainment news comes from. The app lets the user choose the region by setting the query parameter accordingly.


BBC Entertainment feed

edition=uk and edition=us is a Query Parameter.

The values: uk or us determine the content of the feed.


You can pass these query parameter programmatically using EachScape.


How to set up a feed to use a Query Parameter

To generate the descriptor, set up the Live Feed as you would any other through the EachScape platform. We used the name "BBC Feed with Query Parameter". 

In our App Tutorial, we process: http://feeds.bbci.co.uk/news/entertainment_and_arts/rss.xml?edition=uk. 
We processed it with the query parameter but you don't have to. However you need to know the name of the query parameter used by the web service in this case: 'edition' 

We now need to prepare the feed used to accept a query parameter. We are planning to use a query parameter to call the feed associated with a particular region (uk / us).


Query Parameter


While in the Edit section of your feed, right below the Data Description is the section called Query Parameter.


 



Enter the required Parameters (edition) with a matching reference (region)

 


Each query parameter  should be placed on a separate line of this field.
 

The URL call remains unchanged
The question mark (?) and respective parameter(s) will be added automatically.

Having selected 'US' as a region the call will be constructed as follow:

 

feeds.bbci.co.uk/news/entertainement_and_arts/ress.xml?region=us 




Data Source Filter

You MUST instantiate your Data Source with your Query Parameters.


Next, use the Define a Data Source Filter action on that remote data source in your app.

In our Tutorial App, the user sets the Region to UK or US by pressing one of the two buttons labeled accordingly. We store the selected value in a variable displayed on the screen.


 When the user taps the  'Display Results' button the associated event triggers the
Define a Data Source Filter action.

 



Where you use this will depend on the logic of your app: 

  • if the value is the same throughout the app, you can probably just set it once at the beginning. 
  • If it needs to change with every request, put the action in the flow of the app so it will occur before each request. 

When you use this action, you'll need to select "Region" from the dropdown list that specifies which parameter you are setting and the query parameter value. Note that when you do this we will automatically URL-encode the parameter for you.


When you select the 'BBC Feed with Query Parameter' , because you have set that feed with a Query Parameter 'region' the Parameter shows up in the associated drop down menu:

 

 

 
Leave the URL as it is: you do not need to reference the data source in the request.
 
 
When the data source is requested, the edition= parameter will be sent upstream automatically appended to the URL given in the data source.

Learn More
- Make RESTful Calls
- Filter & Search Data in a Feed
SQL DB or Live Feed
- Replacing a Feed name by a variable