Reputation: 14914
Using the Nancy Framework... http://nancyfx.org/
If I want to use the Browser object in the client side to consume Nancy service, like we see in this example: https://github.com/NancyFx/Nancy/wiki/Testing-your-application
...
var bootstrapper = new DefaultNancyBootstrapper();
var browser = new Browser(bootstrapper);
// When
var result = browser.Get("/", with => {
with.HttpRequest();
});
...
Do I have to use Nancy.Testing even though my app is not testing??? In other words, Does other Browser object exist that does Get, Put, Post and Delete Operations like this object does???
Upvotes: 1
Views: 1479
Reputation: 14914
I found the class System.Net.WebClient also does the GET/PUT/POST/DELETE e.g.
//Creating client instance and set the credentials
var client = new WebClient();
client.Credentials = new NetworkCredential(...);
// using GET Request:
var data = client.DownloadData("http://myurl/.../" + docId);
// Using PUT
var data = Encoding.UTF8.GetBytes("My text goes here!");
client.UploadData("http://myurl/...", "PUT", data);
// Using POST
var data = new NameValueCollection();
data.Add("Field1", "value1");
data.Add("Field2", "value2");
client.UploadValues("http://myurl/...", "POST", data);
But, finally I decided to use WCF REST client with webHttpBinding
. Something like this:
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebGet(UriTemplate = "{docId}")]
void GetData(string docId);
}
Concrete Class:
class MyClient: ClientBase<IMyService>, IMyService
{
public void GetData(string docId)
{
Channel.GetData(docId);
}
}
Upvotes: 1
Reputation: 26599
You want something to actually consume the service? Take a look at EasyHttp or RestSharp - they both provide nice APIs for consuming HTTP APIs.
Upvotes: 3