Inheritance

Here we have an interesting idea of what the WebApiClient can do for you: inheritance! Let's see it in action:

public class RestaurantRestClient : WebApiClient<Restaurant>
{
	private static WebApiClientOptions options = new WebApiClientOptions() {
			BaseAddress = "http://localhost/testapi",
			ContentType = ContentType.Xml,
			Timeout = 10000,
			Controller = "restaurants"
	};

    /// <summary>
    /// Creates an instance of RestaurantRestClient using default options
    /// </summary>
	public RestaurantRestClient() : this(options)
	{
	}

    /// <summary>
    /// Creates an instance of RestaurantRestClient using explicit options
    /// </summary>
    private RestaurantRestClient(WebApiClientOptions options) : base(options)
	{
	}

	public async Task<Restaurant> GetRestaurantById(int id)
	{
		try
		{
			return await GetOneAsync(id);
		}
		catch (WebApiClientException e)
		{
			if (e.StatusCode == HttpStatusCode.NotFound)
			{
				return null;
			}
				
			throw e;
		}
	}
		
	public async Task<List<Restaurant>> GetRestaurants()
	{
		return await GetManyAsync();
	}

	public async Task<Restaurant> CreateRestaurant(Restaurant rest)
	{
		return await CreateAsync(rest);
	}

	public async Task<Restaurant> EditRestaurant(Restaurant rest)
	{
		return await EditAsync(rest);
	}

	public async Task DeleteRestaurant(int id)
	{
		await DeleteAsync(id);
	}

	public async Task<List<Restaurant>> GetRestaurantByCountry(int countryId)
	{
		return await GetManyAsync(new { countryId = countryId }, "GetByCountry");
	}
}

Then, you can use this class like this:

using(RestaurantRestClient client = new RestaurantRestClient())
{
	//gets restaurant with id = 1
	Restaurant r = await client.GetRestaurantById(1);

	//gets a list of restaurants
	List<Restaurant> list = await client.GetRestaurantByCountry(12);

	//deletes a restaurant
	client.DeleteRestaurant(123);
}

Neat! Isn't it? ;-)