This repository provides a C# based OData client manager library.
The Manager uses the IODataClient implementation of Simple.OData.Client to communicate with OData APIs and is able to handle authorization and versioning requirements.
The easiest way to start using the ODataManager is to install the Nuget package:
Install-Package OData.Client.ManagerIn the source file where you will be using ODataManager import the namespace:
using OData.Client.Manager;The following code snipped shows an example of how to use the IODataManger implementation.
// Create the manager
var odataEndpoint = new Uri("http://localhost:12345/api");
var manager = new ODataManager(odataEndpoint);
// Use the client of the manager (example of the typed fluent API syntax)
IEnumerable<Product> entities = await manager.Client
.For<Product>()
.FindEntriesAsync();
// Use the client of the manager (example of the dynamic fluent API syntax)
var dx = ODataDynamic.Expression;
IEnumerable<dynamic> entities = await manager.Client
.For(dx.Products)
.FindEntriesAsync();For more information about how to use the Odata client, please read the Simple.OData.Client documentation.
- To make use of authentication use one of the existing authenticators in the
OData.Client.Manager.Authenticatorsnamespace, or create your own by implementing theIAuthenticatorinterface. - To make use of authentication, just use one of the existing managers in the
OData.Client.Manager.Versioningnamespace or create your own by implementing theIVersioningManagerinterface.
// Setup the configuration
var config = new ODataManagerConfiguration(new Uri("http://localhost:12345/api"))
{
// Authenticated requests
Authenticator = new OidcAuthenticator(new OidcSettings
{
AuthUri = new Uri("http://localhost:5000"),
ClientId = "ClientAppX",
ClientSecret = "Secret",
Username = "User",
Password = "Password",
Scope = "api1",
GrantType = "Password", // Default
DiscoveryPolicy = new DiscoveryPolicy { RequireHttps = false },
}),
// Versioned requests
VersioningManager = new QueryParamVersioningManager("1.2", "api-version")
};
// Use the configuration in the ctor of the manager
var manager = new ODataManager(config);- Why do I get the error
Https required?- OIDC endpoints must provide an encrypted connection (https) by default (except URIs of localhost). To disable this requirement, make use of the
OidcSettingsand setRequireHttpsof theDiscoveryPolicyproperty tofalse:settings.DiscoveryPolicy = new DiscoveryPolicy { RequireHttps = requireHttps };.
- OIDC endpoints must provide an encrypted connection (https) by default (except URIs of localhost). To disable this requirement, make use of the
- OData: http://www.odata.org/getting-started or https://docs.microsoft.com/odata
- Simple.OData.Client: https://github.com/simple-odata-client/Simple.OData.Client/wiki
- IdentityModel: https://identitymodel.readthedocs.io
- OIDC: https://openid.net/connect
- Icon made by Freepik