Skip to content

Commit 0605e4d

Browse files
committed
documentation updates
1 parent 3e33888 commit 0605e4d

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

README.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,79 @@
11
# 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+
```
316

417
# 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.
666

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+
```
772

73+
or
874

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+
```

TursoPlatformExtensions.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66

77
namespace TursoPlatformApi
88
{
9+
/// <summary>
10+
/// Extension methods used to setup the Turso platform API for dependency injection.
11+
/// </summary>
912
public static class TursoPlatformExtensions
1013
{
14+
/// <summary>
15+
/// Adds the Turso API services using the configuration from appsettings.json.
16+
/// </summary>
17+
/// <param name="services">The services collection.</param>
18+
/// <returns>The services collection.</returns>
1119
public static IServiceCollection AddTursoPlatformService(this IServiceCollection services)
1220
{
1321
TursoAppSettings appSettings = new TursoAppSettings();
@@ -22,7 +30,7 @@ public static IServiceCollection AddTursoPlatformService(this IServiceCollection
2230

2331
if (tursoSection.Exists())
2432
{
25-
appSettings.DefaultOrganizationSlug = tursoSection["OrganizationSlug"];
33+
appSettings.DefaultOrganizationSlug = tursoSection["DefaultOrganizationSlug"];
2634
appSettings.AuthToken = tursoSection["AuthToken"];
2735
}
2836

@@ -31,6 +39,13 @@ public static IServiceCollection AddTursoPlatformService(this IServiceCollection
3139
return services;
3240
}
3341

42+
/// <summary>
43+
/// Adds the Turso API services using the provided configuration.
44+
/// </summary>
45+
/// <param name="services">The services collection.</param>
46+
/// <param name="organizationSlug">The default organization slug to use when not provided to the method.</param>
47+
/// <param name="authToken">Your Turso platform API auth token.</param>
48+
/// <returns>The services collection.</returns>
3449
public static IServiceCollection AddTursoPlatformService(this IServiceCollection services, string organizationSlug, string authToken)
3550
{
3651
TursoAppSettings appSettings = new TursoAppSettings()

0 commit comments

Comments
 (0)