https://github.com/paysera/dotnet-lib-rest-client-common
https://github.com/paysera/dotnet-lib-rest-client-common
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/paysera/dotnet-lib-rest-client-common
- Owner: paysera
- Created: 2017-03-15T07:39:19.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-02-01T03:23:31.000Z (over 4 years ago)
- Last Synced: 2025-01-03T16:36:59.299Z (5 months ago)
- Language: C#
- Size: 20.5 KB
- Stars: 0
- Watchers: 10
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Paysera Common REST Client for .Net
Provides simple RESTfull Client
### Installation
```
PM> Install-Package Paysera.RestClientCommon
```### Creating ApiClient
Basically you need to create `ApiClient` instance with required configuration.
Here is sample configuration for `ApiClient` using `ClientCertificateAuthentication````csharp
var apiClient = new ApiClient(
new SecureRestClient(
baseUri,
new ClientCertificateAuthentication(
certificateFilePath,
privateKeyFilePath)),
new NoopExceptionMapper());
```##### Parameters
`ApiClient` accepts following arguments:
* `SecureRestClient` accepts following arguments:
* `baseUri` - base uri for this `ApiClient`
* `ClientCertificateAuthentication` accepts following arguments:
* `certificateFilePath` A certificate at path
* `privateKeyFilePath` private key at path
* `password` (optional) will be used to unlock the key
* `ServerCertificateValidator` (optional) - in case you need to verify server certificate manually, accepts following arguments:
* `serverCertificateFilePath` - A certificate at path
* `IExceptionMapper` - you can use existing `NoopExceptionMapper`, which throws `System.Exception` or implement your own if you need to throw custom one.### Usage
This library uses [Newtonsoft.Json](http://www.newtonsoft.com/json/help/html/SerializeObject.htm) for serialization/deserialization between JSON and Objects.
Please read detailed documentation there.```csharp
var transfer = new
{
amount = new
{
amount = 100,
currency = "EUR"
},
beneficiary = new
{
type = "bank",
name = "Name Surname",
bank_account = new
{
iban = "LT12345678901234567890"
}
},
payer = new
{
account_number = "EVP1234567890123"
},
purpose = new
{
details = "Test transfer details"
}
};var result = apiClient.PostAsync("/transfers", transferInput).Task.Result;
```
In example above you can see that you don't have to specify exact types for result and payload objects.
In case you need to use specific types, you just need to specify result and paylod data types: `PostAsync`.
Regular `ApiClient` methods (`Post*`, `Put*`, `Get*`) returns `ApiTask`, where `T` is your requested Type.