Nov 12

Want to learn how test your REST API fluently in a couple of lines of C# code?

Like this:

[Fact]
public async Task Get_UserWithId1_ReturnsDynamicWithUsernameBretAndOkStatusCode()
{
   var client = new RestClient("https://jsonplaceholder.typicode.com", new Config()
                .SetJsonSerializerSettings(new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }));

   await client
      .Resource("users/1").Get()
      .Verify(userIsBret => userIsBret.username == "Bret")
      .Verify(httpResponseMessageIsOk => httpResponseMessageIsOk.HttpResponseMessage.StatusCode == HttpStatusCode.OK);
}

View live example

Head over to my post on Code Maze, and your be testing REST API’s using C# in no time at all.

Tagged with:
Aug 04

Since starting the project in Jan 2015 one of the most asked for features has been full static support (you have always been able to cast responses via duck typing). Inspired by libraries written in dynamic languages like JavaScript and Python – the idea behind RestClient was to reduce the fiction and ceremony when working with Rest API’s, and later on HTTP in general.

I’ve always wanted to add static typing to be more inline with what is expected from a C# library, but wanted to do it in such way that the original concept remained, and that all code is backwards compatible. I’ve now spent the time required to change the package, and this is the result:

DalSoft Rest Client https://github.com/DalSoft/DalSoft.RestClient

Continue reading »

Tagged with:
Feb 22

CodeMaze have written a great post with real world examples of using C# and DalSoft.RestClient to consume any REST API. It includes everything you need to know head over there now if you find yourself writing a lots of boilerplate code to consume REST API’s.

Tagged with:
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:
Jan 26

Whenever I’ve wanted to create a SDK for my WebApi’s I’m surprised by the amount of bolierplate code you end up with. HttpClient made things easier for us, but you still end up wrapping HttpClient and passing generics around.

I wanted something between Simple.Data and angular’s $http service, the main driver was to make my tests as readable as possible. I’ve messed around with .NET 4 dynamic objects before, so I set about creating a dynamic wrapper around HttpClient and a fluent API I could re-use. It’s passed the rule of 3 as I’ve used it for multiple clients. A side note is that it should be trivial to generate DalSoft.RestClient code examples in your WebApi docs.

Continue reading »

Tagged with:
preload preload preload