Painless Http Icon Painless Http HTTP has never been easier

New version available!

PM> Install-Package PainlessHttp -Version 0.11.2

Fork me on GitHub
No external libraries! No over engineered method signatures! No uber verbose setup! Just a HTTP client that is so easy to use that it won't ever give you any headache!


	//instanciate client
	var client = new HttpClient("http://painless.pardahlman.se");

	// create new entity
	var tomorrow = new Todo { Description = "Sleep in", IsCompleted = false};
	var created = await client.PostAsync<Todo>("/api/todos", tomorrow);

	// get it
	var response = await client.GetAsync<Todo>("/api/todos/1");
	var existing = response.Body;

	// update it
	existing.IsCompleted = true;
	var updated = await client.PutAsync<Todo>("/api/todos/1", existing);

	// delete it
	var deleted = await client.DeleteAsync<string>("/api/todos/1");
	if (deleted.StatusCode == HttpStatusCode.OK)
	{
		Console.Write("Successfully deleted todo");
	}
Want to have greater control over how things are done? Just instanciate the client with a Configuration object, and you'll have the posibility to change just about everything:

  //create config
  var config = new Configuration
  {
    BaseUrl = "http://painless.pardahlman.se",
    Advanced =
    {
      Serializers = new List { new PainlessJsonNet() },
      ModifiedSinceCache = new FileCache(cacheDirectory: Environment.CurrentDirectory),
      RequestTimeout = new TimeSpan(days:0, hours:0, minutes:0, seconds:2),
      ContentNegotiation = true,
      Credentials = new NetworkCredential("pardahlman", "strong-password"),
      WebrequestModifier = request => request.Headers.Add("X-Additional-Header", "For each request")
    }
  };
  var client = new HttpClient(config);