From 8d25f17db79d796841194952b03ca3db0c3f3642 Mon Sep 17 00:00:00 2001 From: msanlisavas <80029111+msanlisavas@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:08:10 +0300 Subject: [PATCH] Update README.md --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b84b6a2..7c38313 100644 --- a/README.md +++ b/README.md @@ -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. @@ -93,6 +95,41 @@ 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: @@ -100,6 +137,7 @@ Most of the endpoints require optional request parameters wrapped in a `RequestP 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. @@ -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`.