Jan 26

I was recently asked how to POST a Raw String Body Using DalSoft RestClient, this reminded me that the documentation for DalSoft RestClient is a little out of date.

Updating the docs has been on my todo list for a while now, so I’ve made a new years resolution to get this done. I’m going to start with a series of posts about what you can do with DalSoft RestClient, I’ll then rework these posts into the new docs.

Here’s the first post it’s a quick one – HTTP POST a Raw String Body Using C#

var client = new RestClient("https://your-server/api");
var response = await client.Resource("your-api-resource").Post("string that you want to post");

Yes you can do this as one liner with HttpClient or using one of the plethora of nuget Rest Client Packages, but you would be missing out on easy testing and pipelines then!

Like what you see? There’s a lot more head over to the DalSoft RestClient docs and GitHub Repo.

Tagged with:
Mar 02

Last month I tweeted about a blog post I found interesting:

I thought it was really cool that you could use Razor Components in existing ASP.NET Razor Pages (which is what you build Blazor apps with). I think Razor Pages are one of the easiest ways to develop a web app using ASP.NET Core. Also some things such as authentication are still better served by a ‘traditional web app’ – for example Razor Pages is the default for ASP.NET Identity.

This is why I was glad that this functionality was added to ASP.NET 3.0 Razor Pages and MVC Views, it means a modern alternative to view components and partial views. It also gets you familiar with Razor Components which are the building blocks of a Blazor App.


I have created a nuget package that means in Razor Pages you can use your Razor Components like this:

<hello-world message='$"Hello World {DateTime.Now}"' />

Instead of like this:

<component type="typeof(HelloWorld)" render-mode="Static" param-message='$"Hello World {DateTime.Now}"' />

Continue reading »

Tagged with:
Nov 12

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

Like this:

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

   await client
      .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:
preload preload preload