</figure>
</div>
This project provides early access to advanced or experimental functionality. It may lack usability, completeness, documentation, and robustness, and may be outdated.
However, StrongLoop supports this project. Community users, please report bugs on GitHub.
For more information, see StrongLoop Labs .
</div>
Introduction
Xamarin enables you to create iOS, Android, and Windows mobile client apps from a single C# codebase.
The LoopBack Xamarin SDK includes a tool that creates a Xamarin C# client API based on a LoopBack server backend API. The client API has a standard set of CRUD methods.
In addition, relation methods and custom remote methods in your LoopBack API are generated by the tool as a corresponding C# API.
These are documented in Xamarin client API .
Important:
There are currently some restrictions on support for custom remote methods.
For example, methods with with several return arguments or with multiple body-type parameters are not currently supported.
Also, the SDK doesn’t currently support custom remote methods that return a custom type not exposed in the API.
Non-public Information So, for example, if there’s an inner model called “Email” that hasn’t been defined as public in loopback’s model-config.json, you can’t write custom methods that return an Email model, simply because the
SDK is not privy to it, it doesn’t know there is such a model.</div>
Note:
Although called Xamarin SDK, this SDK is compatible with any C# application.
Download
Get the SDK from GitHub: https://github.com/strongloop/loopback-sdk-xamarin .
$ git clone https://github.com/strongloop/loopback-sdk-xamarin.git
A sample application is at https://github.com/strongloop/loopback-example-xamarin .
Folders Overview
The SDK has the following folders:
C#
- Source code for the C# part of the generator and testers for the entire generator
The open-source of the C# part of the generator, accessed by LBXamarinSDK.sln.
This project’s end result is LBXamarinSDKGenerator.dll
that is placed automatically as a post-build event inside the bin
directory.
bin
- contains the lb-xm
CLI tool.
examples
- contains a LoopBack server and a Xamarin solution of an Android app using the SDK, and a second LoopBack server and a Visual Studio solution of a console application using the SDK.
lib
test-server
- testers for the lb-xm end result that the Testers act upon.
If you need only a functional SDK generator without source code or examples, you need only the folders lib, bin and the files in the root directory.
Using the SDK generator
Set up
On Windows or MacOS:
$ cd loopback-sdk-xamarin
$ npm install
Tip:
By default the SDK generator command will not be installed on your path, so you must either run it from the lbxamarinsdk-generator/bin
directory or provide the full path to it on the command line.
Generating a Xamarin API
To create a Xamarin client based on a LoopBack API:
Create C# code for the SDK; for example:
$ cd bin
$ node lb-xm d:/your-server-app/server/server.js
Where d:/your-server-app/server/server.js
is the full path to your LoopBack application main server script.
The above command shows an example of running the command directly from the lbxamarinsdk-generator/bin
directory.
If you were running the command from another directory, you would instead use (for example):
$ node d:/loopback-sdk-xamarin/bin/lb-xm d:/your-server-app/server/server.js
Important:
You can also run the lb-xm
command with options, to (for example) compile a DLL, add compatibility with Xamarin-Forms, and so on.
See the command reference below for more information.
The generator will save its output in a directory it creates called output
, in the directory where you run the lb-xm
command.
lb-xm command
Use the lb-xm
command to generate a Loopback client in C# based on a LoopBack server API.
The general syntax (when running it in the lbxamarinsdk-generator/bin
directory) is:
node lb-xm path-to-server-script [options]
Tip:
By default the SDK generator command will not be installed on your path, so you must either run it from the
lbxamarinsdk-generator/bin
directory or provide the full path to it on the command line.
ARGUMENTS
path-to-server-script
Full absolute path to the LoopBack application main script.
In the standard project layout , <_app-dir_>/server/server.js
. Required.
OPTIONS
You can provide one or more of the following options:
**dll**
Compile a dll containing the SDK
**forms**
Ensure compatibility with Xamarin-Forms
**force**
Remove unsupported functions
**check**
Check if the SDK compiles successfully as C# code
For example, the following command generates a C# (.cs
) file:
$ node lb-xm c:/testServer/server/server.js
The following command generates a compiled DLL:
$ node lb-xm c:/testServer/server/server.js dll
The command saves the result in the bin/output
folder.