Nov 16
Before 3.3.1 if you wanted to control serialization you would have to decorate your model with attributes, for example if your REST API used snake case naming convention:
public class User
{
[JsonProperty("phone_number")]
public string PhoneNumber { get; set; }
}
As of 3.3.1 you can provide JsonSerializerSettings to the config – this saves you having to add the attributes to properties individually, which will make your code cleaner. For example if your REST API used snake case naming convention:
// When directly creating a RestClient instance
dynamic restClient = new RestClient("https://dalsoft.co.uk", new Config()
.SetJsonSerializerSettings(new JsonSerializerSettings { ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() } }));
// When using IHttpClientFactory
services
.AddRestClient(Name, "https://dalsoft.co.uk")
.SetJsonSerializerSettings(new JsonSerializerSettings { ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() } });
Now the SnakeCaseNamingStrategy ContractResolver is used by default when deserializing responses from your REST API.
To find out more about DalSoft.RestClient including the new JsonSerializerSettings head over to https://restclient.dalsoft.io
Tagged with: csharp • dotnetcore • restclient • serialization
Oct 30
I recently needed to use Twitter’s API along with it’s OAuth 1.0 implementation in .NET Core. As part of this work I created a DalSoft.RestClient Handler, and released it as a full SDK.
Continue reading »
Tagged with: csharp • dotnetcore • restclient • sdk • twitter
Aug 08

Prior to .NET Core 2.1 anyone who has tried to use HttpClient at scale (maybe from a microservice) may have run into the dreaded socket exhaustion issue.
Socket exhaustion happens because HttpClient is designed to be instantiated once and re-used throughout the life of an application, if you make HTTP calls in a server application for every request you will run out of sockets (because sockets get left in TIME_WAIT state for 240 seconds by default).
Using IHttpClientFactory can improve performance by 43%!
Continue reading »
Tagged with: aspnet • aspnetcore • csharp • dotnetcore • httpclient • restclient
May 14
Earlier this year I posted about a pet project I’ve been working on DalSoft.RestClient which is a dynamic C# rest client.
I’ve now used it on a number of projects, and it works really for fluently accessing rest api’s (if I do say so myself). So I thought I’d do a quick post on a real life scenario. For a client of mine I’ve recently needed to integrate PushWoosh, so I thought I’d share some code to show how easy it would be to create a PushWoosh SDK with DalSoft.RestClient.
Continue reading »
Tagged with: ASP.NET • C# • client • dynamic • pushwoosh • rest • restclient • RESTFul • WebApi
Recent Comments