> For the complete documentation index, see [llms.txt](/llms.txt)

# SDK

how to initialize GS2-SDK



To initialize the SDK, you need to create the Credential and Session objects.

## Credential

An object representing a GS2 API key.
The class `BasicGs2Credential` is defined and used when using the API with clientId / clientSecret.

### BasicGs2Credential Parameters

| Argument Name | Description |
| ----- | --- |
| clientId | Client ID |
| clientSecret | Client Secret |

## Session

There are two types of sessions: `Gs2RestSession`, which uses HTTP communication, and `Gs2WebSocketSession`, which uses WebSocket communication.
Depending on the programming language, `Gs2WebSocketSession` may not be supported, and it also has limitations when handling requests with large payloads.
Therefore, if push notifications from the server are not required, `Gs2RestSession` should be used as a general rule.

### Gs2RestSession Request

| Argument Name | Description |
| ----- | --- |
| credential | Credential object |
| region | GS2 Region to connect to |

### Gs2WebSocketSession Request

| Argument Name | Description |
| ----- | --- |
| credential | Credential object |
| region | GS2 Region to connect to |

### Initialization

The created Session object must be connected before use by calling its connection API.




**Go**
```go

    session := core.Gs2RestSession{
        Credential: &core.BasicGs2Credential{
            ClientId: "your client id",
            ClientSecret: "your client secret",
        },
        Region: core.ApNortheast1,
    }

    if err := session.Connect(); err != nil {
        panic("error occurred")
    }
```

**PHP**
```php

    $session = new Gs2RestSession(
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        ),
        Region::AP_NORTHEAST_1
    );

    $session->open();
```

**Java**
```java

    Gs2RestSession session = new Gs2RestSession(
        Region.AP_NORTHEAST_1,
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        )
    );
    session.connect();
```

**C#**
```csharp

    var session = new Gs2RestSession(
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        ),
        Region.ApNortheast1
    );
    yield return session.Open();
```

**TypeScript**
```typescript

    const session = new Gs2Core.Gs2RestSession(
        "ap-northeast-1",
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        )
    );
    await session.connect();
```

**Python**
```python

    session = core.Gs2RestSession(
        core.BasicGs2Credential(
            "your client id",
            "your client secret"
        ),
        "ap-northeast-1",
    )
    session.connect()
```


#### Chaos mode

By calling the SDK initialization process with chaos mode applied, API requests can be made to fail with a certain probability.
Development can proceed using clients with chaos mode enabled to ensure robust error handling.




**C#**
```csharp

    var session = new ChaosGs2RestSession(
        new BasicGs2Credential(
            "your client id",
            "your client secret"
        ),
        0.1f, // 10% chance of error requiring a retry when making an API request
        Region.ApNortheast1
    );
    yield return session.Open();
```



## Clients for microservices

A client is provided for each of the various microservices offered by GS2.
There are also clients for each communication protocol, such as `Gs2AccountRestClient` and `Gs2AccountWebSocketClient`, which require `Gs2RestSession` and `Gs2WebSocketSession` respectively.

### Gs2AccountRestClient Request

| Argument Name | Description |
| ----- | --- |
| session | Gs2RestSession |

### Gs2AccountWebSocketClient Request

| Argument Name | Description |
| ----- | --- |
| session | Gs2WebSocketSession |

### Implementation Example




**Go**
```go

client := account.Gs2AccountRestClient{
    Session: &session,
}
```

**PHP**
```php

$client = new Gs2AccountRestClient($session);

```

**Java**
```java

Gs2AccountRestClient client = new Gs2AccountRestClient(session);

```

**C#**
```csharp

var client = new Gs2AccountRestClient(session);
```

**TypeScript**
```typescript

const client = new Gs2Account.Gs2AccountRestClient(session);

```

**Python**
```python

client = account.Gs2AccountRestClient(session)

```





