NetClient.Rest
An asynchronous REST API client that allows you to make API calls using LINQ syntax. Note: Add, edit, and delete functionality is coming soon.
See the assembly help documentation for help on usage and code samples.
Create a class that models the return data. Support for JsonSerializationSettings is built-in for more precise control of how data is serialized and deserialized.
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
}
Create a client for the API you want to abstract.
[BaseUri("https://customer-api-server")]
public class CustomerClient : RestClient
{
[Route("/customers/{CustomerId}")]
public Resource<Customer> Customers { get; set; }
//... add a property for each resource to support.
}
Use linq (query or method) syntax to interact with the API.
private static void Main(string[] args)
{
var client = new CustomerClient { OnError = ex => Console.WriteLine(ex.Message) };
var customers = from c in client.Customers where c.CustomerId == 417260 select c;
// API call is made at enumeration.
var customer = customers.ToArray().SingleOrDefault();
Console.WriteLine($"ID: {customer?.CustomerId}");
Console.WriteLine($"Name: {customer?.Name}");
Console.ReadKey();
}
See the source code for more detailed sample.