Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
msanlisavas authored Jul 1, 2024
1 parent ca8a144 commit 8d25f17
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@ The `CasperCloudRestClient` class provides an easy way to interact with the CSPR

To create an instance of the `CasperCloudRestClient`, you need to provide your API key. Optionally, you can also pass a custom `HttpClient` and `ILoggerFactory` for logging purposes.

#### Step-by-Step Guide

1. **Add Dependencies**

### Step-by-Step Guide

### 1. **Add Dependencies**

Ensure you have the necessary dependencies in your project. Typically, this includes:
- `HttpClient`
- `ILoggerFactory` from Microsoft.Extensions.Logging

2. **Create a Configuration Class**
### 2. **Create a Configuration Class**

Create an instance of the `CasperCloudClientConfig` class with your API key.

Expand Down Expand Up @@ -93,13 +95,49 @@ var accountData = await restClient.Testnet.Account.GetAccountAsync("public-key")
// Accessing the Block endpoint on Mainnet
var blockData = await restClient.Mainnet.Block.GetBlockAsync("block-hash");
```
### 5. Dependency Injection Example

#### appsettings.json
```
"CsprCloud": {
"ApiKey": "your-api-key"
}
```

```
context.Services.AddSingleton(resolver =>
{
var apiKey = configuration.GetSection("CsprCloud:ApiKey").Value;
return new CasperCloudRestClient(new CasperCloudClientConfig(apiKey));
});
```
Then call using di
```
public class IndexModel : PageModel
{
private readonly CasperCloudRestClient _restClient;
public IndexModel(CasperCloudRestClient restClient)
{
_restClient = restClient;
}
public async Task OnGet()
{
var result = await _restClient.Mainnet.Account.GetAccountInfoAsync("bb436216f3f56b073fc712c024a01c1291292e9533a03ddabc67ef85360b00bf");
}
}
```


## Using Parameterized Requests on Endpoints

Most of the endpoints require optional request parameters wrapped in a `RequestParameters` class, which includes three possible components:
1. **FilterParameters**: Used to filter the results.
2. **SortingParameters**: Used to sort the results.
3. **OptionalParameters**: Used to include additional data in the results.


### Example Usage

Parameters and properties differ for each request depending on the endpoint.
Expand Down Expand Up @@ -134,6 +172,8 @@ var parameters = new ValidatorsRequestParameters
var result = await _restClient.Testnet.Validator.GetValidatorsAsync(parameters);
```



### Samples

Below are some examples of demonstrating how to use the `CasperCloudRestClient`.
Expand Down

0 comments on commit 8d25f17

Please sign in to comment.