This library let you to interact with a CKan server APIs with dedicated clients.
==========
- Add nuget package:
Install-Package CKan.NetClient.Unoficial
- CI configuration. In your startup file, you must register an HttpClient by using the HttpClientFactory and next register the custom CKan client by calling the AddCKanClient method.
private void Register(this IServiceCollection services)
{
// Define the baseUri of your organization :
var baseUri = "https://sample.com/ckan";
// Register the HttpClientFactory :
services.AddHttpClient()
// Register the CKanClient object :
services.AddCKanClient(baseUri);
}
If you have a named HttpClient, you can use it. Ex : You can use it to mock Http calls :
private void Register(this IServiceCollection services)
{
// Register the HttpClientFactory :
services.AddHttpClient("customName")
.ConfigurePrimaryHttpMessageHandler(() =>
{
// custom handler
});
// Register the CKanClient object with the named http client
services.AddCKanClient(baseUri, "customName");
}
- Now in your application you can use the CKanClient object from the DI or directly from the service provider :
public CkanClient GetClient(IServiceProvider serviceProvider)
{
return serviceProvider.GetRequiredService<CKanClient>();
}
public class MyHttpController
{
private readonly CkanClient client;
public MyHttpController(CkanClient client)
{
this.client = client;
}
}
Each API has his own client that let you to read and manipulate datas. Each API is linked to an interface named : I<Api name>Client.
Ex for groups :
public IGroupsClient GetGroupsClient(CkanClient client)
{
return serviceProvider.GetClient<IGroupsClient>();
}
This interface let you to read groups, get group details, ...
- Groups : IGroupsClient
- Organizations : IOrganizationsClient
- Packages : IPackagesClient
- Tags : ITagsClient
Only read operations are avaiable yet. But more functions will be developped soon. Do not hesitate to participate.
Do not hesitate to check unit tests on the solution. It's a good way to check client calls and samples.
Do not hesitate to contribute.
If you have any questions, problems or suggestions, create an issue or fork the project and create a Pull Request.