Skip to content

AutoRest clients

The AutoRest tool generates client libraries for accessing Virto Commerce API.

Installing the Autorest


Read the official AutoRest documentation: Installing AutoRest

  • Install Node.js (12.19.x LTS preferred. May not function with Node < 10.x.)
  • Install AutoRest using npm, at the moment using version 3.0.x, because the Platform generate the api as OpenApi 3.0.x.
    npm install -g autorest
  • Then reset autorest cache:
    autorest --reset

Generating C# Clients with AutoRest

  • Have the platform run locally (10645 port by default)
  • Generate autorest client on the Storefront
  • Open Tools > NuGet Package Manager > Package Manager Console
  • Run the following commands to generate API clients:
    $modules = @('Platform', 'Cart', 'Catalog', 'Content', 'Core', 'Customer', 'Inventory', 'Marketing', 'Notifications', 'Orders', 'Payment', 'Pricing', 'Shipping', 'Sitemaps', 'Store', 'Subscription', 'Tax')
    $modules.ForEach( { autorest VirtoCommerce.Storefront\AutoRestClients\array-in-query-fix.yml --version=3.0.6274 --v3 --debug --input-file=http://localhost:10645/docs/VirtoCommerce.$_/swagger.json --output-folder=.\VirtoCommerce.Storefront\AutoRestClients --output-file=$_`ModuleApi.cs --namespace=VirtoCommerce.Storefront.AutoRestClients.$_`ModuleApi --override-client-name=$_`ModuleClient --add-credentials --csharp })
  • Add the api client to the ServiceColection:
    services.AddAutoRestClient((credentials, httpClient, disposeHttpClient, baseUri) => new TaxModuleApi(credentials, httpClient, disposeHttpClient) { BaseUri = baseUri });
    services.AddSingleton<ITaxModule>(sp => new TaxModule(sp.GetRequiredService<TaxModuleApi>()));

Last update: January 17, 2022