deveel - Deveel.Rest.Client 1.0.0-r00023

Deveel REST Client

PM> Install-Package Deveel.Rest.Client -Version 1.0.0-r00023 -Source https://www.myget.org/F/deveel/api/v3/index.json

Copy to clipboard

> nuget.exe install Deveel.Rest.Client -Version 1.0.0-r00023 -Source https://www.myget.org/F/deveel/api/v3/index.json

Copy to clipboard

> dotnet add package Deveel.Rest.Client --version 1.0.0-r00023 --source https://www.myget.org/F/deveel/api/v3/index.json

Copy to clipboard
<PackageReference Include="Deveel.Rest.Client" Version="1.0.0-r00023" />
Copy to clipboard
source https://www.myget.org/F/deveel/api/v3/index.json

nuget Deveel.Rest.Client  ~> 1.0.0-r00023
Copy to clipboard

> choco install Deveel.Rest.Client --version 1.0.0-r00023 --source https://www.myget.org/F/deveel/api/v2

Copy to clipboard
Import-Module PowerShellGet
Register-PSRepository -Name "deveel" -SourceLocation "https://www.myget.org/F/deveel/api/v2"
Install-Module -Name "Deveel.Rest.Client" -RequiredVersion "1.0.0-r00023" -Repository "deveel" -AllowPreRelease
Copy to clipboard

Browse the sources in this package using Visual Studio or WinDbg by configuring the following legacy symbol server URL: https://www.myget.org/F/deveel/symbols/


Build status MyGet NuGet

Deveel REST Client (DRest)

This is a simple .NET Core client library for interacting with REST services, making it easy to construct and invoke HTTP requests in a dynamic way.

Install the Library

Building a Client

To build a REST client with DRest is an easy process and it can be done with a straight constructor of RestClientSettings (or any class deriving from IRestClientSettings) or using a builder.

In this example, we will use a building strategy:

var client = RestClient.Build(settings => settings
                .BaseUri("http://api.example.com")
                .UseJsonSerializer()
                .UseDefaultHeader("X-DeviceId", "9999999999"));

The base URI of the service to contact is required in a building context, while when contructing the client using a reference to IHttpClient that value can be inferred from that low-level client.

By default, RestClientSettings includes all the default IContentSerializer instances defined by the library: if in the builder one or more specific serializers are specified to be used, the settings is cleared out by the default serializers and the explicitly specified are used.

Making a Request

The library provides the class RestRequest as the core element for constructing a REST request to a remote service: this includes parameters (Header, Route, QueryString, Body and File) and request-specific authentication.

It is also provided a building model for constructing requests dynamically

var request = RestRequest.Build(builder => builder
      .Get()
      .To("user/{userId}")
      .WithRoute("userId", 25)
      .Returns<User>());
      
var response = await client.RequestAsync(request);

var user = await response.GetBodyAsync<User>();

Extensions to the IRestClient provide utilities for building requests directly when sending the request.

var response = client.SendAsync(request => request
        .Post()
        .To("user/{userId}/setting")
        .WithRoute("userId", 101)
        .WithJsonBody(new UserSetting{Key="notify",Value=true})
        .WithHeader("X-Source", "iOS App"));

Content Serializers

The content (body) of a request or a response is serialized/deserialized by the client using implementations of IContentSerializer, selected by the analysis of the content type of a response or from an explicit specification of the request setup (either specifying the type of content posted or by using the default content defined in the client settings).

DRest defines some default implementations of the serializers

  • JsonContentSerializer: it is used to serialize datain or from JSON contents; it uses the Newtonsoft JSON.NET library as lower level serializer
  • XmlContentSerializer: handles requests and responses of XML formatted contents
  • KeyValueContentSerializer: although the www-form-urlencoded format is not explicitly recommended in REST model, this serializer is a utility when passing multi-parted content to a remote service (eg. additional data to an image file)

Authentication

Requests to a remote service can be optionally authenticated, given a strategy defined from implementations of IRequestAuthenticator: when specified, in the client settings or in the request settings, this is invoked before any request is sent to the remote service.

var client = RestClient.Build(builder => builder
      .BaseUri("http://api.example.com")
      .UseJwtAuthentication(token));
      
  ....
  
var response = client.SendAsync(request => request
      .Get()
      .To("token")
      .WithQueryString("grant_type", "password")
      .WithQueryString("username", "tester")
      .WithQueryString("password", "abc1234")
      .Authenticate(false));
      
var response2 = client.SendAsync(request => request
      .Get()
      .To("docs")
      .UseBasicAuthentication("developer", "dev1234")
      .Returns<dynamic>());

The request-level authenticator overrides any authentication configured at client-settings level, if any. It is also possible to request that a specific request is not authenticated: in this case none of the authenticators specified will be invoked.

  • .NETStandard 1.6
    • NETStandard.Library (>= 1.6.1)
    • Newtonsoft.Json (>= 9.0.1)
    • System.Runtime.Extensions (>= 4.3.0)
    • System.Runtime.Serialization.Primitives (>= 4.3.0)
    • System.Xml.XmlSerializer (>= 4.3.0)
  • .NETStandard 1.6: 1.6.0.0

                        
Assembly Assembly hash Match
/lib/netstandard1.6/deveel.rest.client.dll 931d6e1120474a569f90bdaebfc63cff1

Owners

Antonello Provenzano

Authors

Antonello Provenzano

Project URL

https://github.com/deveel/drest

License

MIT

Tags

rest,http,deveel,web,client,json,xml

Info

4 total downloads
0 downloads for version 1.0.0-r00023
Download (37.39 KB)
Download legacy symbols (129.89 KB)
Found on the current feed only

Package history

Version Size Last updated Downloads Mirrored?
1.0.0-r00023 37.39 KB Sat, 11 Mar 2017 20:01:04 GMT 0
1.0.0-r00022 37.34 KB Sat, 11 Mar 2017 19:20:24 GMT 0
1.0.0-r00021 37.14 KB Sat, 11 Mar 2017 17:48:49 GMT 0
1.0.0-r00020 37.09 KB Sat, 11 Mar 2017 17:20:52 GMT 0
1.0.0-r00019 37.08 KB Sat, 11 Mar 2017 17:19:38 GMT 0
1.0.0-r00018 37.07 KB Mon, 06 Mar 2017 22:54:27 GMT 0
1.0.0-r00017 37.07 KB Mon, 27 Feb 2017 13:33:06 GMT 1
1.0.0-r00016 35.89 KB Mon, 27 Feb 2017 12:11:18 GMT 0
1.0.0-r00015 29.02 KB Sat, 25 Feb 2017 18:13:28 GMT 0
1.0.0-r00014 29.01 KB Sat, 25 Feb 2017 18:06:48 GMT 0
1.0.0-r00013 29 KB Sat, 25 Feb 2017 17:52:55 GMT 0
1.0.0-r00012 29 KB Sat, 25 Feb 2017 17:37:58 GMT 0
1.0.0-r00011 28.92 KB Sat, 25 Feb 2017 17:16:34 GMT 1
1.0.0-r00010 28.93 KB Sat, 25 Feb 2017 16:22:43 GMT 1
1.0.0-r00009 28.52 KB Sat, 25 Feb 2017 12:53:52 GMT 0
1.0.0-r00008 27.34 KB Sat, 25 Feb 2017 10:57:05 GMT 0
1.0.0-r00007 27.14 KB Sat, 25 Feb 2017 10:37:20 GMT 0
1.0.0-r00006 27.13 KB Sat, 25 Feb 2017 09:48:04 GMT 0
1.0.0-r00005 27.09 KB Sat, 25 Feb 2017 09:11:28 GMT 0
1.0.0-r00004 26.74 KB Sat, 25 Feb 2017 01:57:36 GMT 1
1.0.0-r00003 26.34 KB Sat, 25 Feb 2017 01:26:26 GMT 0
1.0.0-r00002 24.34 KB Fri, 24 Feb 2017 18:43:59 GMT 0