├── .gitattributes ├── .gitignore ├── Painless.Html ├── icon.png └── index.html ├── Painless.Serializer.JsonNet.NuGet └── Painless.Serializer.JsonNet.NuGet.nuproj ├── PainlessHttp.DevServer ├── App.config ├── Controllers │ ├── FeatureController.cs │ └── TodoController.cs ├── Data │ ├── ITodoRepository.cs │ ├── InMemoryTodoRepo.cs │ └── RequestRepo.cs ├── Model │ └── Todo.cs ├── PainlessHttp.DevServer.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Startup.cs └── packages.config ├── PainlessHttp.IntegrationTests ├── Features │ ├── AuthenticationTests.cs │ ├── ContentNegotiationTests.cs │ ├── ErrorStatusCodeTests.cs │ ├── ModifiedSinceTests.cs │ └── RequestTimeoutTests.cs ├── Methods │ ├── DeleteTests.cs │ ├── GetTests.cs │ ├── PerformRawTests.cs │ ├── PostTests.cs │ └── PutTests.cs ├── PainlessHttp.IntegrationTests.csproj ├── Properties │ └── AssemblyInfo.cs ├── WebApiSetupFixture.cs └── packages.config ├── PainlessHttp.Nuget └── PainlessHttp.Nuget.nuproj ├── PainlessHttp.Sandbox ├── App.config ├── PainlessHttp.Sandbox.csproj ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── PainlessHttp.Serializer.JsonNet.Tests ├── PainlessHttp.Serializer.JsonNet.Tests.csproj ├── PainlessJsonNetTests.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── PainlessHttp.Serializer.JsonNet ├── NewtonSoft.cs ├── NewtonsoftSettings.cs ├── PainlessHttp.Serializer.JsonNet.csproj ├── PainlessJsonNet.cs ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── PainlessHttp.Tests ├── PainlessHttp.Tests.csproj ├── Properties │ └── AssemblyInfo.cs ├── Serializers │ ├── Custom │ │ ├── SerializeSettingsTests.cs │ │ └── SerializerTests.cs │ ├── SerializerTestClasses.cs │ └── Typed │ │ ├── DefaultJsonSerializerTests.cs │ │ └── DefaultXmlSerializerTests.cs ├── Utils │ ├── AcceptHeaderMapperTests.cs │ ├── ClientUtilsTests.cs │ ├── ContentNegotiatorTests.cs │ ├── HttpConverterTests.cs │ ├── ResponseTransformerTests.cs │ └── UrlBuilderTests.cs └── packages.config ├── PainlessHttp.sln ├── PainlessHttp ├── Cache │ ├── CacheBase.cs │ ├── CachedObject.cs │ ├── FileCache.cs │ ├── IModifiedSinceCache.cs │ ├── InMemoryCache.cs │ └── NoCache.cs ├── Client │ ├── Configuration.cs │ ├── HttpClient.cs │ └── IHttpClient.cs ├── Http │ ├── AcceptHeaderField.cs │ ├── ContentType.cs │ ├── Contracts │ │ ├── IHttpResponse.cs │ │ └── IHttpWebResponse.cs │ ├── HttpMethod.cs │ ├── HttpResponse.cs │ └── HttpWebResponse.cs ├── Integration │ ├── ResponseTransformer.cs │ └── WebRequester.cs ├── PainlessHttp.csproj ├── Properties │ └── AssemblyInfo.cs ├── Serializers │ ├── Contracts │ │ └── IContentSerializer.cs │ ├── Custom │ │ ├── CustomSerializer.cs │ │ ├── Serializer.cs │ │ └── SerializerBulider.cs │ ├── Defaults │ │ ├── ContentSerializers.cs │ │ ├── DefaultJson.cs │ │ └── DefaultXml.cs │ └── Typed │ │ ├── DefaultJsonSerializer.cs │ │ ├── DefaultNoActionSerializer.cs │ │ └── DefaultXmlSerializer.cs └── Utils │ ├── AcceptHeaderMapper.cs │ ├── ClientUtils.cs │ ├── ContentNegotiator.cs │ ├── HttpConverter.cs │ ├── UrlBuilder.cs │ └── WebRequestBuilder.cs └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # * text=auto 2 | 3 | *.csproj -text merge=union 4 | *.sln -text merge=union 5 | 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs) 2 | [Bb]in/ 3 | !performance-tests/jmeter/bin/ 4 | [Oo]bj/ 5 | 6 | # mstest test results 7 | TestResults 8 | 9 | # NCrunch files 10 | _NCrunch_PainlessHttp 11 | **/*.v2.ncrunchproject 12 | *v2.ncrunchsolution 13 | 14 | ## Ignore Visual Studio temporary files, build results, and 15 | ## files generated by popular Visual Studio add-ons. 16 | 17 | # User-specific files 18 | *.suo 19 | *.user 20 | *.sln.docstates 21 | 22 | # Build results 23 | [Dd]ebug/ 24 | [Rr]elease/ 25 | x64/ 26 | *_i.c 27 | *_p.c 28 | *.ilk 29 | *.meta 30 | *.obj 31 | *.pch 32 | *.pdb 33 | *.pgc 34 | *.pgd 35 | *.rsp 36 | *.sbr 37 | *.tlb 38 | *.tli 39 | *.tlh 40 | *.tmp 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.nupkg 46 | 47 | # Visual C++ cache files 48 | ipch/ 49 | *.aps 50 | *.ncb 51 | *.opensdf 52 | *.sdf 53 | 54 | # Visual Studio profiler 55 | *.psess 56 | *.vsp 57 | *.vspx 58 | 59 | # NuGet Packages Directory 60 | packages 61 | 62 | SeleniumTests/Reports 63 | SeleniumTests/*.jar 64 | -------------------------------------------------------------------------------- /Painless.Html/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pardahlman/PainlessHttp/796a0e5f49b844cfa95e0b93b1ebf982c05c4337/Painless.Html/icon.png -------------------------------------------------------------------------------- /Painless.Html/index.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |25 | 26 | 27 |
31 | PM> Install-Package PainlessHttp -Version 0.11.2
32 |
GET
, POST
, PUT
and DELETE
with typed responsesIf-Modified-Since
caches for speeding up your application even more.PainlessHttp.Serializers.JsonNet
)System
, System.Core
, System.Runtime.Serialization
and System.Xml
)
45 | //instanciate client
48 | var client = new HttpClient("http://painless.pardahlman.se");
49 |
50 | // create new entity
51 | var tomorrow = new Todo { Description = "Sleep in", IsCompleted = false};
52 | var created = await client.PostAsync<Todo>("/api/todos", tomorrow);
53 |
54 | // get it
55 | var response = await client.GetAsync<Todo>("/api/todos/1");
56 | var existing = response.Body;
57 |
58 | // update it
59 | existing.IsCompleted = true;
60 | var updated = await client.PutAsync<Todo>("/api/todos/1", existing);
61 |
62 | // delete it
63 | var deleted = await client.DeleteAsync<string>("/api/todos/1");
64 | if (deleted.StatusCode == HttpStatusCode.OK)
65 | {
66 | Console.Write("Successfully deleted todo");
67 | }
68 |
69 |
70 | 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:
71 | //create config
74 | var config = new Configuration
75 | {
76 | BaseUrl = "http://painless.pardahlman.se",
77 | Advanced =
78 | {
79 | Serializers = new List { new PainlessJsonNet() },
80 | ModifiedSinceCache = new FileCache(cacheDirectory: Environment.CurrentDirectory),
81 | RequestTimeout = new TimeSpan(days:0, hours:0, minutes:0, seconds:2),
82 | ContentNegotiation = true,
83 | Credentials = new NetworkCredential("pardahlman", "strong-password"),
84 | WebrequestModifier = request => request.Headers.Add("X-Additional-Header", "For each request")
85 | }
86 | };
87 | var client = new HttpClient(config);
88 |
89 |
90 |
91 |