DISCLAIMER: THIS IS SAMPLE CODE AND NOT PRODUCTION QUALITY CODE!
Before running this sample, the BookService sample needs to be running locally on your computer or published to the cloud. For more information, see BookService.
This sample is a client application that makes HTTP requests to the BookService project. You can view, create, edit and delete books stored in a Mongo backend database via the BookService.
This sample runs on either Android 4.0 (API 14) and later, or iOS 7 and later; and was tested against Appcelerator CLI 4.0, Appcelerator Studio 4.0 and Titanium SDK 4.0.0.GA.
Importing the Project into Studio
Clone this repo, create a new Alloy project, then import the cloned repo into the newly created Alloy project.
- From the menu bar, select File > New > Mobile Project. The New Mobile Project wizard appears.
- Select Alloy > Default Alloy Project. Click Next.
- Fill out all fields and click Finish.
- From the menu bar, select File > Import. The Import wizard appears.
- Select General > File System. Click Next.
- For From directory, click Browse, navigate to the cloned repo, then click Open.
- Select the app folder, that is, checkmark the item.
- For Into directory, click Browse, select the newly created project, then click OK.
- Click Finish.
Studio creates a new Alloy project and imports the files into it.
Configure the REST Sync Adapter
- Change the
config.adapter.base_urlkey to the endpoint URL of the BookService, for example,
- Change the
config.adapter.api_keykey to the API key of the application. The value should match one of the
apikeyvalues in the Arrow configuration file.
- Change the
config.adapter.auth_typekey to match the value of the
APIKeyAuthTypein the Arrow configuration file.
NOTE: When running the BookService project locally, you cannot use
the value of the
Running the Client Application
Before running the client application, the BookService project either needs to be running locally on your computer or published to the cloud.
- Select your project in the App Explorer or Project Explorer view.
- Click the Run button and select either the Android Emulator or iPhone Simulator.
Studio launches the client application on the selected platform.
Testing the Client Application
The client application uses the native controls of the Android and iOS platform to add a book or refresh the table.
- For Android, in the action bar, select
Addto add a book or
Refreshto refresh the view.
- For iOS, use the window's right navigation button (
Add) to add a book and drag the table down to refresh the view.
To close a window, use the Back button on the Android platform and the window's left navigation button on the iOS platform.
To modify or delete a book, click on the book title in the table, then:
- To modify the book, make your modifications and click Save Edits.
- To delete the book, click Remove.