Skip to content

Latest commit

 

History

History
197 lines (193 loc) · 7.3 KB

COMPARISON.md

File metadata and controls

197 lines (193 loc) · 7.3 KB

Comparison between DotNet Core SDK V2 and V1

Why I should use V2 SDK

The SDK V2 has some features which is not exists in V1 like:

  • V1 only supports the Composable Commerce HTTP API, but V2 has different packages to support the Import API, Machine Learning API, and the Change History API.
  • V2 SDK supports ME endpoints.
  • V2 SDK is auto generated from RAML files like other SDKS which means less maintainability and it will be always up-to-date with backend new features.
  • V2 SDK is faster than V1 SDK as it’s using System.Text.Json in Serialization and Deserialisation
  • In SDK V1, you only have to configure clients and inject them in the service container in the App Start, but SDK V2, you can use the injected clients or use the ClientFactory to create clients on the fly.

Comparison of SDK Installation

Package V2 V1
HTTP API dotnet add package commercetools.Sdk.Api dotnet add package commercetools.Sdk.All
Import API dotnet add package commercetools.Sdk.ImportApi
Machine Learning API dotnet add package commercetools.Sdk.MLApi
Change History API dotnet add package commercetools.Sdk.HistoryApi

Comparison of SDK Services Configuration

After packages installation, you have to configure services using Dependency Injection Setup in the application Startup.cs

Package V2 V1
HTTP API services.UseCommercetoolsApi(this.configuration, "Client"); services.UseCommercetools(
this.configuration,"Client");
Import API services.UseCommercetoolsImportApi(this.configuration, "ImportClient");
Machine Learning API services.UseCommercetoolsMLApi(this.configuration, "MLClient");
Change History API services.UseCommercetoolsHistoryApi(this.configuration, "HistoryClient");

Comparison of how to make requests to the Composable Commerce HTTP API

    // Create CategoryDraft
    var categoryDraft = new CategoryDraft
                {
                    Name = new LocalizedString {{"en", "Name"}},
                    Slug = new LocalizedString {{"en", "Slug"}},
                    Key = "Key"
                };
    // Create CategoryUpdate
    var action = new CategoryChangeNameAction
                    {
                        Name = new LocalizedString {{"en", "newName"}}
                    };
    var categoryUpdate = new CategoryUpdate
                    {
                        Version = category.Version,
                        Actions = new List<ICategoryUpdateAction> { action }
                    };
Request V2 V1
Create var category = await projectApiRoot .Categories() .Post(categoryDraft) .ExecuteAsync(); var category = await client .Builder() .Categories() .Create(categoryDraft) .ExecuteAsync();
Get By Id var queriedCategory = await projectApiRoot .Categories() .WithId(category.Id) .Get() .ExecuteAsync(); var queriedCategory = await client .Builder() .Categories() .GetById(category.Id) .ExecuteAsync();
Get By Key var queriedCategory = await projectApiRoot .Categories() .WithKey(category.Key) .Get() .ExecuteAsync(); var queriedCategory = await client .Builder() .Categories() .GetByKey(category.Key) .ExecuteAsync();
Query var response = await projectApiRoot .Categories() .Get() .WithWhere($"key = \"{category.Key}\"") .ExecuteAsync(); var response = await client .Builder() .Categories() .Query() .Where(c => c.Key == category.Key.valueOf()) .ExecuteAsync();
Delete By Id var deletedCategory = await projectApiRoot .Categories() .WithId(category.Id) .Delete() .WithVersion(category.version) .ExecuteAsync(); var category = await client .Builder() .Categories() .DeleteById(category) .ExecuteAsync();
Delete By Key var deletedCategory = await projectApiRoot .Categories() .WithKey(category.Key) .Delete() .WithVersion(category.version) .ExecuteAsync(); var category = await client .Builder() .Categories() .DeleteByKey(category.Key, category.Version) .ExecuteAsync();
Update var updatedCategory = await projectApiRoot .Categories() .WithId(category.Id) .Post(categoryUpdate) .ExecuteAsync(); var updatedCategory = await client .Builder() .Categories() .UpdateById(category) .AddAction(action) .ExecuteAsync();