Generated C# OpenApi Client for Camunda
Nuget package: https://www.nuget.org/packages/Camunda.OpenApi.Client/
Camunda Version | Camunda.OpenApi.Client Version | HTTP library |
---|---|---|
7.17.0 | 1.3.0 | HttpClient |
7.16.0 | 1.2.1 | HttpClient |
7.16.0 | 1.2.0 | RestSharp |
7.15.0 | 1.1.0 | RestSharp |
7.14.0 | 1.0.1 | RestSharp |
var config = new Configuration();
config.BasePath = "http://localhost:8080/engine-rest";
var apiInstance = new TaskApi(config);
try
{
var result = apiInstance.GetTasks();
result.ForEach(item => Console.WriteLine(item.ToString()));
}
catch (ApiException e)
{
Debug.Print(e.StackTrace);
}
You can implement your own Extension with your settings:
public static class CamundaClientExtension
{
public static void AddCamundaClient(this IServiceCollection services)
{
var config = new Configuration
{
BasePath = "http://localhost:8080/engine-rest",
UserAgent = "CamundaClient"
};
// enable Basic Authentication
// var credentials = Encoding.ASCII.GetBytes("demo:demo");
// config.DefaultHeaders["Authorization"] = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(credentials)).ToString();
// add all needed api's
services.AddSingleton(new TaskApi(config));
services.AddSingleton(new TaskVariableApi(config));
services.AddSingleton(new ProcessInstanceApi(config));
services.AddSingleton(new ProcessDefinitionApi(config));
services.AddSingleton(new DeploymentApi(config));
services.AddSingleton(new MessageApi(config));
services.AddSingleton(new HistoricProcessInstanceApi(config));
services.AddSingleton(new HistoricActivityInstanceApi(config));
}
}
Add services.AddCamundaClient();
in Startup.cs on the ConfigureServices
method:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddCamundaClient();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo {Title = "TestWebApp", Version = "v1"});
});
}
Now you can inject the api services everywhere in your application. Example:
[ApiController]
[Route("[controller]")]
public class ExampleController : ControllerBase
{
private readonly TaskApi _taskApi;
public ExampleController(TaskApi taskApi)
{
_taskApi = taskApi;
}
[HttpGet]
public IEnumerable<TaskDto> Get()
{
return _taskApi.GetTasks();
}
}