The AutoREST utility is used to generate a REST API Client in the Xamarin project from the Swagger definitions exposed by the ePortal Web API endpoint URL. The client proxy and the associated data models are generated as C# classes in the Xamarin project.
The AutoRest utility automatically generates an HTTP REST API client module and scaffolds data models for the project. This can be used to send requests to the ePortal WebAPI from your Xamarin App.
Note: You can include multiple REST interfaces into your Xamarin app, which may be required to integrate data from different sources. AutoREST generates a separate set of model definitions and an HTTP client for use with each external service. However, the Xamarin scaffolding for ePortal can only be used for a service exposed by an ePortal Web API, and only one of these can be scaffolded for each Xamarin Forms project.
To create a REST API Client from an ePortal Web API, perform the following steps:
Notes:
The ePortal Web API should be based on the .NET Framework version. The ePortal .NET Core Web API is currently not supported for creating Xamarin Forms.
If you have access to a Swagger document for the REST Service, skip to step 2.
From the deployed ePortal Web API, download the Swagger definition, and do the following:
Using a browser, navigate to the URL where the REST Service is running and request for the Swagger UI page. For example: http://myWebAPIUrl/MyWebAPI/Swagger/ui/index.
This page displays the URL needed to access the Swagger document for the Service. For example: http://myWebAPIUrl/SampleAPI/swagger/docs/v1.
Navigate to the documentation URL.
The Swagger definition for the service is displayed in the browser. Now, you can save this as a file, for input to the REST API Client generation process. Since the format is in JSON notation, it is recommended to save the file with a .json file type.
In the Visual Studio Solution Explorer, right-click the Xamarin project, and select Generate Unisys ePortal Rest API Client.
Note: In Visual Studio for MAC, the menu item is located under the Project menu, instead of the right-click context menu.
The Add REST API Specification dialog box appears.
In the Add REST API Specification dialog box, click Browse… to select an existing Swagger metadata file, and click OK.
This initiates the AutoREST generation process and you will see the associated progress output in the Visual Studio output window. Once the generation completes, you can see a new folder structure in the common project, that contains all the model files and http client modules corresponding to the imported service definition.
Now you must compile the project before you can scaffold the Views, Viewmodels and infrastructure files, as described in Scaffolding XAML Views and View Models.