|
1 | 1 | # About |
2 | | -This is an unofficial SDK for using the [Turso Platform API](https://docs.turso.tech/api-reference/introduction) in C#. It currently supports all available `v1` endpoints. |
| 2 | +This is an unofficial SDK for using the [Turso Platform API](https://docs.turso.tech/api-reference/introduction) in C#. It supports all available `v1` endpoints. |
| 3 | + |
| 4 | +# Setup |
| 5 | +Complete setup information can be found in the [Turso quickstart guide](https://docs.turso.tech/api-reference/quickstart). |
| 6 | + |
| 7 | +1. First [install the Turso CLI](https://docs.turso.tech/cli/installation). |
| 8 | +2. Use the CLI to get your account user or organization slug. |
| 9 | + ``` |
| 10 | + turso org list |
| 11 | + ``` |
| 12 | +3. Create a platform API token. |
| 13 | + ``` |
| 14 | + turso auth api-tokens mint quickstart |
| 15 | + ``` |
3 | 16 |
|
4 | 17 | # Usage |
5 | | -There are a few different ways to use the |
| 18 | +First install the package: |
| 19 | +``` |
| 20 | +dotnet add package rthomasv3.TursoPlatformApi |
| 21 | +``` |
| 22 | + |
| 23 | +The services and methods are a one-to-one mapping with the Turso documentation. |
| 24 | + |
| 25 | +For example, to list all databases: |
| 26 | +```c# |
| 27 | +await tursoPlatformService.Databases.List(); |
| 28 | +``` |
| 29 | + |
| 30 | +| Service | Usage | |
| 31 | +| ------------- | ------------- | |
| 32 | +| ITursoPlatformService | The overall platform service with properties for all other services. | |
| 33 | +| ITursoDatabaseService | Manage databases. | |
| 34 | +| ITursoGroupService | Manage groups. | |
| 35 | +| ITursoLocationService | View locations. | |
| 36 | +| ITursoOrganizationsService | Manage organizations. | |
| 37 | +| ITursoMembersService | Manage members. | |
| 38 | +| ITursoInvitesService | Manage invites. | |
| 39 | +| ITursoAuditLogsService | View audit logs. | |
| 40 | +| ITursoApiTokensService | Manage platform API tokens. | |
| 41 | + |
| 42 | +The easiest way to use the Turso Platform API Service is using dependency injection. |
| 43 | + |
| 44 | +## Dependency Injection |
| 45 | +Add a `TursoPlatformApi` section to your `appsettings.json` file. Use `appsettings.Development.json` to avoid keys ending up in your repo. |
| 46 | + |
| 47 | +```json |
| 48 | +{ |
| 49 | + "TursoPlatformApi": { |
| 50 | + "DefaultOrganizationSlug": "<your-organization-slug>", |
| 51 | + "AuthToken": "<your-api-token>" |
| 52 | + } |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +After that you can add Turso Platform API Service using the provided services extension method. |
| 57 | + |
| 58 | +```c# |
| 59 | +builder.Services.AddTursoPlatformService(); |
| 60 | +``` |
| 61 | + |
| 62 | +Then you can add any of the API services to the constructors in your application. |
| 63 | + |
| 64 | +## Instance |
| 65 | +You can also create and use an instance directly if you prefer. |
6 | 66 |
|
| 67 | +```c# |
| 68 | +// create a new instance |
| 69 | +var tursoPlatformApi = new TursoPlatformApi.TursoPlatformService("<your-organization-slug>", "<your-api-token>"); |
| 70 | +var allGroups = await tursoPlatformApi.Groups.List(); |
| 71 | +``` |
7 | 72 |
|
| 73 | +or |
8 | 74 |
|
| 75 | +```c# |
| 76 | +// static instance |
| 77 | +TursoPlatformApi.TursoPlatformService.Initialize("<your-organization-slug>", "<your-api-token>"); |
| 78 | +var allDatabases = await TursoPlatformApi.TursoPlatformService.Instance.Databases.List(); |
| 79 | +``` |
0 commit comments