NetEatr 0.0.5

dotnet add package NetEatr --version 0.0.5
NuGet\Install-Package NetEatr -Version 0.0.5
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetEatr" Version="0.0.5" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetEatr --version 0.0.5
#r "nuget: NetEatr, 0.0.5"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetEatr as a Cake Addin
#addin nuget:?package=NetEatr&version=0.0.5

// Install NetEatr as a Cake Tool
#tool nuget:?package=NetEatr&version=0.0.5

<p align="center"> <img width="128" height="192" src="net.eatr.png"/> </p>

NetEatr

RESTful web service consumer for .Net


Changelog

for changelog check here


Features

  • Builder pattern
  • Auto encode param and form url encoded body
  • Auto parsed raw body from stream object to String
  • Auto parsed JSON using Newtonsoft library
  • Support synchronous or asynchronous operation
  • Support progress observer

Requirements

  • .Net Standar 2.0

Installation

Nuget

  1. Go to Nuget package manager on visual studio
  2. Search NetEatr
  3. Install

Package Manager

run this on package manager console

Install-Package NetEatr -Version 0.0.5

.Net CLI

run this on .Net CLI

dotnet add package NetEatr --version 0.0.5

Manually

  1. Clone this repository.
  2. Added to your project.
  3. Congratulation!

Usage Example

Synchronous

Build the object using HttpRequestBuilder and then execute
If your response contains some Json, you can pass your Model as Generic attribute

//HttpGet
Response response = HttpRequestBuilder.HttpGet.SetUrl("http://your.url.here")
    .AddHeaders("SOME-HEADER", "header_value").AddParam("param_key", "param_value").AwaitExecute();
    
boolean isSuccess = response.IsSuccess;
boolean hadException = response.hadException;
int statusCode = response.StatusCode;
string body = response.RawBody;

//HttpPost with Json response and Json body
RestResponse<Model> response = HttpRequestBuilder.HttpPost.SetUrl("http://your.url.here")
    .AddHeaders("SOME-HEADER", "header_value").AddParam("param_key", "param_value")
    .AddJsonBody(someObject).AwaitExecute<Model>();

Model responseObj = response.JsonBody;

Simple Asynchronous

Everything is same like synchronous, but instead of call AwaitExecute, call AsyncExecute
You can even pass onFinished delegate to run after request is finished

//Basic
HttpRequestBuilder.HttpGet.SetUrl("http://your.url.here")
    .AddHeaders("SOME-HEADER", "header_value").AddParam("param_key", "param_value")
    .AsyncExecute();
    
//With delegate
HttpRequestBuilder.HttpGet.SetUrl("http://your.url.here")
    .AddHeaders("SOME-HEADER", "header_value").AddParam("param_key", "param_value")
    .AsyncExecute((response) => {
        //YOUR CODE HERE
        // WILL BE EXECUTE AFTER REQUEST IS FINISHED
    });

//Using RestResponse
HttpRequestBuilder.HttpGet.SetUrl("http://your.url.here")
    .AddHeaders("SOME-HEADER", "header_value").AddParam("param_key", "param_value")
    .AsyncExecute<Model>((restResponse) => {
        //YOUR CODE HERE
        // WILL BE EXECUTE AFTER REQUEST IS FINISHED
        //restResponse is RestResponse<Model> object
    });

Advanced

Same like any http request, but you can set your delegate consumer separately. you can set 5 consumer:

  • SetOnProgress which will run for every progress, it will give the progress in float start from 0.0f to 1.0f
    Because this method will called periodically, its better if you're not put object creation inside this method
  • SetOnBeforeSending which will run before sending
  • SetOnResponded which will ONLY run when you get response
  • SetOnTimeout which will ONLY run when you get no response after timeout
  • SetOnException which will ONLY run when you get unhandled exception

You don't need to set all of the consumer. just the one you need. Is up to you if you want to execute it using AsyncExecute or AwaitExecute

HttpRequestBuilder.HttpPost.SetUrl("http://your.url.here")
    .AddHeaders("SOME-HEADER", "header_value").AddParam("param_key", "param_value")
    .AddJsonBody(someObject)
    .SetOnTimeout(() => {
        //YOUR CODE HERE
    })
    .SetOnBeforeSending((httpWebRequest) => {
        //httpWebRequest is HttpWebRequest object which will executed before sending
        //You can manipulate this before sending
        //YOUR CODE HERE
    })
    .SetOnException((exception) => {
        //YOUR CODE HERE
    })
    .SetOnProgress((progress) => {
        //progress is float range from 0 - 1
        //YOUR CODE HERE
    })
    .SetOnResponded((response) => {
        //response is Response object
        //if you pass Generic parameter it will be RestResponse<Parameter> object
    })
    .AsyncExecute((response) => {
        //YOUR CODE HERE
        // WILL BE EXECUTE AFTER REQUEST IS FINISHED
    })

Contribute

We would love you for the contribution to NetEatr, just contact me to nayanda1@outlook.com or just pull request

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.5 981 2/25/2018
0.0.3 894 2/24/2018

added getter setter for simpler approach