This tutorial is going to show you how to build a Windows 8 app in Appery.io new app builder. Before proceeding, here are a few things to keep in mind:
- The new builder is now in beta.
- You should use Firefox to build and test the app in the browser. IE10 support is coming
In this tutorial, we are going to build a Windows 8 app to search Twitter. We will use the Twitter search REST API to find all tweets using a term entered in the app.
Creating a new Windows 8 project
To start, let’s create a new Windows 8 project.
- Sign into Appery.io.
- Click on APPS in the upper-right-hand corner of the screen.
- Click on the More create options link to the right of the Create button.
- In the new screen, enter an app name. Let’s use “TwitterWindows8”.
- Select the Windows 8 App radio button.
- Click Create to open the new project in the new builder. (It should display a welcome screen as shown below.)
Creating the UI
We will create the UI by dragging and dropping components from a left sidebar palette and setting component properties from a right-hand sidebar.
- Using the left sidebar, expand Pages and select home. In the middle of the screen, you will see this:
- Click the black screen.
- In the right (Properties) sidebar under Custom, find the Rows field and make the entry “120px;auto;1fr”. A new row will appear.
- From the Design (components) palette to the left, select an input component under Controls and drop it inside the cell at the first row/second column:
The result will then look like this:
- Select the new input and then click the icon (as shown) to select the parent container:
- Under Custom properties, set Column align to “start”.
- Now select a button component from under Controls and drop it inside the cell at the second row/second column.
- Select the new button’s parent container by clicking the icon as you did for the new input and set Column align to “start”.
- Select the button and change its label by entering “Search” into the Text field under Common properties.
- You can also now test the app by clicking the Test button in the upper-right corner of the browser screen.
Note: We recommend Firefox for previewing the app. We are still working on IE 10 support.
- Now, let’s continue building the UI by adding a listview component. Select a listview component from the Containers components and then drop it inside the cell at the third row/second column.
- Select the component and, under Common properties, change the Height to “160px”.
- Next, select a grid component from the Layouts components and drop it inside the listview.
- With the grid selected, set the Rows field under Custom properties to “auto;auto;auto”.
- Then, set its size by entering these values into these fields under Commonproperties:
- Width: “600px”
- Height: “160px”
- Select an image component from the Controls components and drop it into the first row/first column of the grid you just created.
- Select the image component’s parent (via the small icons) and set its Column align to “start”.
- Select a label component from the Controls components and drop it into the second row/first column of the grid.
- Select the label’s parent (via the small icons) and set its Column align to “start”.
- Reselect the label and set the Text field under Common properties to be blank.
- Select another label component from the Controls components and drop it into the third row/first column of the grid.
- Select this label’s parent (via the small icons) and set its Column align to “start”.
- Then, reselect the label and set the Text field under Common properties to be blank.
(Saving is not required till the end, but, if you want, you can save at the end of each section by clicking on the Save button in the top menu bar of the editor.)
Creating a service
We’ll now create a Appery.io “service” component (service interface) that can be used in building our app. We’ll use a Twitter Search REST service for our service component. We just need to define some things about the service and specify the request and response parameter we’ll be using for input and output.
- In the upper-left part of the screen, click on Create New and then click on “Service” from the drop-down menu.
- Enter “TwitterSearch” as the name and click the Create Service button.
- If you look on the left-hand side, you’ll see the new service listed under Services. Click on this TwitterSearch label to open the service editor on the service.
- Now, under the REST Service Properties section, enter “http://search.twitter.com/search.json” as the URL and select “jsonp” as the Data Type.
- Open the Request Parameters section underneath this section by clicking on Request Parameters.
- Enter “q” into the text input box and click Add.
- Open the Response Parameters section underneath this section by clicking on Response Parameters.
- Enter “results” into the text input box and click Add.
- Click the green + button in the same row as the results response parameter to make a sub-element of results.
- Enter “profile_image_url” into the new text input box and click Add. The result will look like this:
- Click the green + button in the same row as the results response parameter again to make another sub-element of results.
- Enter “from_user” into the new text input box and click Add.
- Then, click the green + button in the same row as the results response parameter one last time to make another sub-element of results.
- Enter “text” into the new text input box and click Add.
The result will look like this:
Mapping the service to the UI
Now, we have REST service parameters on one side and UI components on the other side. Next, we’ll connect them together in the Data section of the editor as a data mapping called “restservice” that uses the service component called “TwitterSearch”.
- Select the home tab above the service editor.
- Click on the Data side-tab.
- From the Type drop-down menu, select “Service”.
- From the Component drop-down menu, select “REST Service”.
- Click the green button to the right.
- In the row that will have appeared under Components List, click the blue Edit Mapping… button
- A Component Properties sidebar will appear to the right. From the Service drop-down menu, select “TwitterSearch”.
- Now click the Edit Mapping… button again. A new screen, the mapping editor, will scroll in from the right with the Request Mapping tab selected.
- On the right-hand side under Components, expand home and then expand the first sub-item under it.
- Click on the q parameter on the left-hand side, drag the cursor to the label Text under the expanded sub-item, and drop.
The input component is now mapped to the REST service input.
- Now click on the Response Mapping.
- Expand results on the the left-hand side, collapse the input component on the right-hand side, and expand the listview component and it’s subitems until everything is exposed.
- Then, using the same drag-and-drop approach as above, define the following mappings:
The results parameter is the collection of all tweets found through the query. We are mapping it to the parent listview container to get automatic looping. The rest of the mappings are straightforward.
Invoking the service
We are almost done. We have a UI, a service component for using a REST service from the app, and a data mapping connecting the UI and the service together. All we need is a triggering event for the data mapping to invoke the service. For this we’ll use a panel hidden away at the bottom of the screen.
- Select the Design side-tab.
- Find the Show Events Panel tab all the way in the bottom-right corner of your screen.
- Click this tab to open the events panel.
- From the Component drop-down menu, select the button component.
- From the Event drop-down menu, select “Click”.
- From the Action drop-down menu, select “Invoke Service”.
- From the Service drop-down menu select “restservice” (the service data mapping you created).
- Click the green button to add this event.
You have now set up the app to invoke a service through clicking the Search button in the app.
Testing the app
Now we can test the app. Just click the Test button in the upper-right corner of the screen and enter any term to search for. You should get a result that looks something like this: