Consuming API from the MAUI Application - ChrispyPeaches/FocusFriends GitHub Wiki

Configure API Client for API Consumption

When developing locally, ensure the API:

  1. Is using the HTTPS protocol, and
  2. Is deployed at "https://localhost:7282"

The API uses the "localhost" url in order to match the host name in the auto-generated self-signed SSL certificate required for HTTPS connections.

Within the FocusApp, the connection to the FocusAPI is configured in MauiProgram.cs under the RegisterRefitClient method. This method configures an HttpClient in the service collection with the help of some HTTP helper extensions in the case of a local FocusAPI. It also supports connection to a remotely deployed FocusAPI when not in debug mode.

The helper extensions are located in FocusApp.Client.DevHttp.DevHttpHelperExtensions.cs. These helper methods facilitate a connection to a locally deployed HTTPS FocusAPI with android specific functions.

Best Practices for Consuming API on MAUI Pages

The event methods used internally by MAUI may be overridden to allow for calls to the API. These methods are inherited from the "ContentPage" class.

  • See the "Performance Tips" section of the documentation for details on how to offload API calls off of the main (UI) thread

For example, the "OnAppearing" method can be overridden to allow custom code to run once the page appears. Methods like these will be our "hooks" into consuming information from the API upon events within the application.

Additional research is required to determine best practices for calling the API from the MAUI application.