|
| 1 | +## AndroidStudio ServiceStack Plugin |
| 2 | + |
| 3 | +ServiceStackIDEA is a plugin for AndroidStudio to make working with ServiceStack services easier when building Android apps. |
| 4 | + |
| 5 | +Using this plugin, you can add a ServiceStack reference to your existing Android application which generates required POJOs for interactive with the specific ServiceStack server. |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +Once added, the plugin also adds a reference to the ServiceStack.Android library which uses the ServiceStack.Client Java library to to make HTTP requests. |
| 10 | + |
| 11 | +``` |
| 12 | +AndroidServiceClient client = new AndroidServiceClient("http://techstacks.io"); |
| 13 | +client.getAsync(new AppOverview(), new AsyncResult<AppOverviewResponse>() { |
| 14 | + @Override |
| 15 | + public void success(AppOverviewResponse response){ |
| 16 | + appOverviewResponse = response; |
| 17 | + onUpdate(DataType.AppOverview); |
| 18 | + } |
| 19 | + }); |
| 20 | +``` |
| 21 | + |
| 22 | +This reduces the amount of code required when interacting with ServiceStack web services and also reduces guesswork around request and response types by using the generated POJOs. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +#### Add a ServiceStack Reference |
| 27 | + |
| 28 | +To add a ServiceStack reference, right click on a file or folder inside your project module. |
| 29 | +> Alternatively, select the module/package folder/Java file and press **Ctrl+Alt+Shift+R**. |
| 30 | +
|
| 31 | + |
| 32 | + |
| 33 | +If you right click of an existing Java class (with a package) or package folder, the package field will be populated automatically. |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +Then provide the base URL to the ServiceStack server. This is usually the domian where your ServiceStack application is hosted. |
| 38 | + |
| 39 | +Also, you can change the required file name for where the POJOs will be stored. |
| 40 | + |
| 41 | +The Java file will then be added to the related package or `/src/main/java` folder of the module. If it has not already been added, the Module's `build.gradle` dependencies will be updated with the `net.servicestack:android` client dependency. |
| 42 | + |
| 43 | +#### Update ServiceStack Reference |
| 44 | + |
| 45 | +Once you have added a ServiceStack reference, it can be easily updated by using AndroidStudio `Intension` shortcut, usually Alt+Enter when in the file. |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +This will read all of the used options in the commented file header to generate a new request. This can be handy if the server has been updated and you need to update your client side POJOs, or if you want to include get/set methods by default. |
| 50 | + |
| 51 | +For documentation on all options for both server and client, see the Java Add ServiceStack Reference wiki page. |
0 commit comments