Generate API client¶
This guide describes the process of generating an API client to access the VC Platform API from your custom application.
Note
Platform Manager REST Client offers generated REST API methods that make it easy to interact with the existing VirtoCommerce Platform API.
Prerequisites¶
- .NET Core 6.0, particularly if you are using MacOS or Linux.
Generate TypeScript API clients¶
To enable TypeScript API client generation in your project:
-
Make sure your project has the necessary dependencies, if not - add dependencies to your project:
cross-env
runs scripts that set and use environment variables across platforms. -
Configure client generation in your project. Inside your project's package.json file, add a
"generate-api-client"
command to the list of scripts:vc-app-extend/package.json The options are listed in the table below:
Options Description Type Example --APP_PLATFORM_MODULES
Platform modules with namespaces to generate API client.
Customize the--APP_PLATFORM_MODULES
list
to match your project's requirements.string[]=
--APP_PLATFORM_MODULES='[Virtocommerce.MarketplaceVendor,Virtocommerce.Orders,Virtocommerce.Catalog]'
--APP_API_CLIENT_DIRECTORY
Output directory for generated API clients. string
--APP_API_CLIENT_DIRECTORY=./src/api_client/
--APP_PLATFORM_URL
Platform URL to obtain client API configs. string
--APP_PLATFORM_URL=https://vcmp-dev.govirto.com/
-
Configure Platform URL to ensure your project can access the platform's API configurations. Add the platform URL to your project's .env file:
Note
Alternatively, you can specify the Platform URL as a command option in the previous step when running the
generate-api-client
command. -
Generate the API clients using the following command:
This command generates the required API clients for your custom application. Now you can effortlessly access the VC Platform API from your custom application using the generated API client.