|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +nav_order: 5 |
| 4 | +title: Configuration |
| 5 | +--- |
| 6 | + |
| 7 | +## Configuration |
| 8 | + |
| 9 | +### ConnectionInfo |
| 10 | + |
| 11 | +All clients require a `ConnectionInfo` object: |
| 12 | + |
| 13 | +```csharp |
| 14 | +var conn = new ConnectionInfo |
| 15 | +{ |
| 16 | + FmsUri = "https://your-server.com", |
| 17 | + Database = "YourDatabase", |
| 18 | + Username = "admin", |
| 19 | + Password = "password" |
| 20 | +}; |
| 21 | +``` |
| 22 | + |
| 23 | +#### REST API Version |
| 24 | + |
| 25 | +Set `RestTargetVersion` to target a specific Data API version: |
| 26 | + |
| 27 | +```csharp |
| 28 | +conn.RestTargetVersion = RestTargetVersion.v1; // default |
| 29 | +conn.RestTargetVersion = RestTargetVersion.v2; |
| 30 | +conn.RestTargetVersion = RestTargetVersion.vLatest; |
| 31 | +``` |
| 32 | + |
| 33 | +### Creating a Client Directly |
| 34 | + |
| 35 | +```csharp |
| 36 | +var client = new FileMakerRestClient(new HttpClient(), conn); |
| 37 | +``` |
| 38 | + |
| 39 | +### Using Dependency Injection |
| 40 | + |
| 41 | +#### Standard (Scoped) Lifetime |
| 42 | + |
| 43 | +Register `IFileMakerApiClient` with `AddHttpClient` for managed `HttpClient` lifetime: |
| 44 | + |
| 45 | +```csharp |
| 46 | +services.AddSingleton<ConnectionInfo>(new ConnectionInfo |
| 47 | +{ |
| 48 | + FmsUri = "https://your-server.com", |
| 49 | + Database = "YourDatabase", |
| 50 | + Username = "admin", |
| 51 | + Password = "password" |
| 52 | +}); |
| 53 | + |
| 54 | +services.AddHttpClient<IFileMakerApiClient, FileMakerRestClient>(); |
| 55 | +``` |
| 56 | + |
| 57 | +This creates a new `FileMakerRestClient` per scope (typically per HTTP request in ASP.NET Core). |
| 58 | + |
| 59 | +#### Singleton Lifetime |
| 60 | + |
| 61 | +For better performance when making many Data API calls per request, register as a singleton: |
| 62 | + |
| 63 | +```csharp |
| 64 | +services.AddHttpClient(); // register IHttpClientFactory |
| 65 | +
|
| 66 | +services.AddSingleton<ConnectionInfo>(new ConnectionInfo |
| 67 | +{ |
| 68 | + FmsUri = "https://your-server.com", |
| 69 | + Database = "YourDatabase", |
| 70 | + Username = "admin", |
| 71 | + Password = "password" |
| 72 | +}); |
| 73 | + |
| 74 | +services.AddSingleton<IFileMakerApiClient, FileMakerRestClient>(sp => |
| 75 | +{ |
| 76 | + var hcf = sp.GetRequiredService<IHttpClientFactory>(); |
| 77 | + var ci = sp.GetRequiredService<ConnectionInfo>(); |
| 78 | + return new FileMakerRestClient(hcf.CreateClient(), ci); |
| 79 | +}); |
| 80 | +``` |
| 81 | + |
| 82 | +The singleton approach reuses the FileMaker Data API token across requests, reducing authentication overhead. |
| 83 | + |
| 84 | +### FileMaker Cloud Authentication |
| 85 | + |
| 86 | +For FileMaker Cloud (Claris Connect), use `FileMakerCloudAuthTokenProvider`: |
| 87 | + |
| 88 | +```csharp |
| 89 | +var conn = new ConnectionInfo |
| 90 | +{ |
| 91 | + FmsUri = "https://yourhost.account.filemaker-cloud.com", |
| 92 | + Database = "YourDatabase", |
| 93 | + Username = "user@domain.com", |
| 94 | + Password = "password" |
| 95 | +}; |
| 96 | + |
| 97 | +var client = new FileMakerRestClient( |
| 98 | + new HttpClient(), |
| 99 | + new FileMakerCloudAuthTokenProvider(conn)); |
| 100 | +``` |
| 101 | + |
| 102 | +`FileMakerCloudAuthTokenProvider` handles authentication via AWS Cognito. The default Cognito settings are pre-configured for FileMaker Cloud: |
| 103 | + |
| 104 | +| Property | Default | |
| 105 | +|---|---| |
| 106 | +| `CognitoUserPoolID` | `us-west-2_NqkuZcXQY` | |
| 107 | +| `CognitoClientID` | `4l9rvl4mv5es1eep1qe97cautn` | |
| 108 | +| `RegionEndpoint` | `us-west-2` | |
| 109 | + |
| 110 | +Override these on `ConnectionInfo` if your FileMaker Cloud instance uses different values. |
| 111 | + |
| 112 | +For a full description of using the FileMaker Data API with FileMaker Cloud, see [this discussion](https://github.com/fuzzzerd/fmdata/issues/217#issuecomment-1203202293). |
0 commit comments