.NET Rest Client Frameworks

2019-02-08 14:37发布

问题:

I'm looking for the best .NET C# framework for building a REST Http client. My requirements are as follows:

  • Unit testable (mockable)
  • Supports multi-part form and file uploads

I have looked at Hammock, but it is lacking in documentation and seems to be troublesome when attempting to mock file uploads.

Any suggestions, please?

回答1:

I have just submitted a patch for the aforementioned problem with mocking file uploads using Hammock and has been accepted into the trunk. See issue 13 for more details.



回答2:

There is also RestSharp. I've inherited it on some projects and haven't fully explored it myself, so I'm afraid I cannot say if it meets your requirements.

The developer of RestSharp is active in the .Net community, so if the published documentation doesn't cover something I would say there is a good chance of getting some assistance.



回答3:

You can also take a look to Spring.Rest client Framework : http://springframework.net/index.html#spring-rest-1.0.0-released



回答4:

Also take a look at the Microsoft.Http client in http://wcf.codeplex.com/ It will be included in future versions of the framework. It is relatively easy to unit test with.



回答5:

Microsoft HTTP Client Libraries is good option to consider.

Nuget URL - https://www.nuget.org/packages/Microsoft.Net.Http/



回答6:

This is a stretch but you can try out my library - IEnterprise.Easy-HTTP, since it using generic builders and you can customise the building process, which would make it easier for testing, it also has some built in stuff like class parsing and query building:

await new RequestBuilder<ExampleObject>()
.SetHost("https://httpbin.org")
.SetContentType(ContentType.Application_Json)
.SetType(RequestType.Post)
.SetModelToSerialize(dto)
.Build()
.Execute();

Feel free to ask questions or check the code in github :)



标签: .net http rest