ServiceStack

About ServiceStack: Http Client and Http Utils

ServiceStack Repo stars is similar to Flurl in that it is a very simple REST library and also offers on a Fluent API. ServiceStack.HttpClient is part of a huge ServiceStack suite.

ServiceStack offers several implementations: Http Utils (Fluent API based on a string (like Flurl)), or also specific clients, like for Json with the JsonServiceClient (Http Client).

Info Link
License proprietary
Downloads Nuget
Latest Version GitHub release (latest by date)
Issues GitHub issues
Contributors GitHub contributors

Http Client

The Http Client is ServiceStack’s recommended package for HTTP clients, especially for its own products. However, you can use the client for any Json-based REST API.

IServiceClient client = new JsonHttpClient("my-rest-api.com");

// Get single task
TaskApiModel? task = await client.GetAsync<TaskApiModel?>("tasks/123");

// Get all tasks
List<TaskApiModel> tasks = await client.GetAsync<List<TaskApiModel>>("tasks");

// Add new task
TaskApiCreateModel newTask = new TaskApiCreateModel { Title = "Buy flowers" };
TaskApiModel addedTask = await client.PostAsync<TaskApiModel>("tasks", newTask);

The big advantage is that the library is attached to a powerful product and additional built-in features like caching and debug print are provided.

Http Utils

The Http Utils are aimed by ServiceStack primarily at APIs that do not provide a ready-made SDK and behaves similarly to Flurl.

// Get single task
string taskResponse = await "my-rest-api.com/task/123".GetJsonFromUrlAsync();
TaskApiModel? task = taskResponse.FromJson<TaskApiModel?>();

// Get all tasks
string tasksResponse = await "my-rest-api.com/tasks".GetJsonFromUrlAsync();
List<TaskApiModel> tasks = tasksResponse.FromJson<List<TaskApiModel>>();

// Add new task
TaskApiCreateModel newTask = new TaskApiCreateModel { Title = "Buy flowers" };
string addedTaskResponse = await "my-rest-api.com/tasks".PostJsonToUrlAsync(newTask);
TaskApiModel addedTask = addedTaskResponse.FromJson<TaskApiModel>();

The biggest disadvantage of utils is that any serialization must be programmed yourself and you have little to no type safety.

Comparison

Full Sample

See the full sample on GitHub: https://github.com/BenjaminAbt/dotnet.rest-samples