Provides simple RESTfull Client
PM> Install-Package Paysera.RestClientCommon
Basically you need to create ApiClient
instance with required configuration.
Here is sample configuration for ApiClient
using ClientCertificateAuthentication
var apiClient = new ApiClient(
new SecureRestClient(
baseUri,
new ClientCertificateAuthentication(
certificateFilePath,
privateKeyFilePath)),
new NoopExceptionMapper());
ApiClient
accepts following arguments:
SecureRestClient
accepts following arguments:baseUri
- base uri for thisApiClient
ClientCertificateAuthentication
accepts following arguments:certificateFilePath
A certificate at pathprivateKeyFilePath
private key at pathpassword
(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 existingNoopExceptionMapper
, which throwsSystem.Exception
or implement your own if you need to throw custom one.
This library uses Newtonsoft.Json for serialization/deserialization between JSON and Objects. Please read detailed documentation there.
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<object, object>("/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<TResult, TPayload>
.
Regular ApiClient
methods (Post*
, Put*
, Get*
) returns ApiTask<T>
, where T
is your requested Type.