TABLE OF CONTENTS
- Introduction
- Prerequisites
- Environment Setup
- Step 1: Setting Up the Znode API Locally
- Step 2: Installing and Restoring NuGet Packages
- Step 3: Setting the Startup Project in Visual Studio
- Step 4: Configuring the appsettings.json file of the V1 and V2 API for the Local Environment as follows.
- Step 5: Connecting to DB environments
- Step 6: Run the Project
- Enable Caching
Introduction
This article gives details on the setup of your Z10 API local development environment. It includes step-by-step instructions for installing required dependencies and configuring services. Use this guide as a starting point to easily build, test, and integrate API functionalities.
Prerequisites
Before you begin, ensure the following tools are installed on your system:
- Download and Install Visual Studio:
- Visit the official website: https://visualstudio.microsoft.com
- Download the latest version of Visual Studio (Community, Professional, or Enterprise). These extensions help improve code quality, consistency, and readability:
- Recommended (optional but helpful) Visual Studio extensions:
- ? CodeMaid: A powerful tool for cleaning and organizing your code automatically.
- ? Visual Studio Spell Checker: Helps detect spelling errors in your comments, strings, and text files.
- Steps to install from the Visual Studio extension or download from the provided URLs.
- Open Visual Studio
- Go to Extensions > Manage Extensions
- Search for each extension by name and click Download
- Restart Visual Studio to complete the installation
- Downloadable Link:
Links :
? CodeMaid download and install: Download Link
? Visual Studio Spell Checker download and install: Download Link
Environment Setup
Step 1: Setting Up the Znode API Locally
- Access the Repository:
- Repository name: znode10-api-migration
- Ensure you have the necessary permissions to access the repo.
- Clone the Repository:
- Open your terminal or Git Bash.
- Run the following command:
- git clone https://<your-repo-url>/znode10-api-migration.git
- Replace <your-repo-url> with your actual repository link.
- Set Up Locally:
- Navigate to the cloned folder:
cd znode10-api-migration
- Navigate to the cloned folder:
Step 2: Installing and Restoring NuGet Packages
- Open Your Visual Studio Solution.
- Launch Visual Studio and open the solution file (.sln) of your project from Znode.Multifront folder.
- Configure NuGet Package Source
- Go to Tools > NuGet Package Manager > Package Manager Settings.
- Select Package Sources
- Click the + button to add a new source:
- Znode NuGet Source
- Name: Znode NuGet
- Source URL: https://nuget.znode.com/nuget
Authentication (if prompted): - Username: znode-mission@mrrsoft.com
- Password: xxxxx ( you can get the password from the Znode support team)
- GitHub NuGet Source (MRRSoft)
- Name: ZnodeDevQaGit
- Source URL: https://nuget.pkg.github.com/mrrsoft/index.json
Authentication (if prompted): You can get the credentials from the Znode support team
Username: user@amla.io
Password: xxxxxxxxx
Step 3: Setting the Startup Project in Visual Studio
To run the Multifront API(V1 and V2 API), you need to set the correct projects as the startup project in Visual Studio:
- Open the Solution in Visual Studio.
- In Solution Explorer, locate the project file:
Znode.Engine.Api.csproj. - Right-click on the project and select:
- "Configure the Startup Project"
- Select “Znode.Engine.Api”, “Znode.Engine.ApiV2”, and set action as Start. Apply the changes and click on “Ok”.
- The project names should appear in bold, indicating they will run when you start the projects.
Step 4: Configuring the appsettings.json file of the V1 and V2 API for the Local Environment as follows.
- Open the appsettings.json file from Znode.Engine.Api project.
- To enable functionality across admin, multifront APIs, and other components, configure the respective URLs as detailed below.
- "AdminWebsiteUrl": "https://admin-qa-znode.amla.io",
- "ZnodeApiGateway": "https://apigateways-qa-znode.amla.io",
- "PluginApiRootUri": "https://plugin-server-qa-znode.amla.io",
- "CustomAPIRootUri": "https://customapi-z10-dev.amla.io",
- "ZnodeApiRootUri": "https://api-qa-znode.amla.io",
- "ZnodeApiV2RootUri": "https://localhost:54546",
- Configure the Elastic Search URL as per your Elastic Search service configuration.
E.g., "ElasticSearchRootUri": "http://localhost:9200" - Open Znode.Engine.ApiV2 project, open appsettings.json file, and repeat the same settings mentioned in the above steps to keep connections in sync.
Note: Make sure all related microservices use the correct local URIs in their appsettings.json.
Step 5: Connecting to DB environments
Configuring Database Connection Strings in appsettings.json
To connect your application to your local database, you need to replace the existing cloud-based connection strings with your local SQL Server credentials in the appsettings.json file.
- Open the appsettings.json file of the V1 API project, i.e., Znode.Engine.Api project.
- Update the ConnectionStrings Section
- Replace the current Azure connection strings with your local machine’s SQL Server details:
- Server: Name of your local SQL instance (e.g., localhost\SQLEXPRESS or just localhost)
- Catalog: Your database name
- User ID and Password: Your local DB credentials
- E.g.
"ConnectionStrings": { "ZnodeECommerceDB": "Server=localhost;Initial Catalog=YourDBName;User ID=your_username;
Password=your_password;TrustServerCertificate=True;",
"Znode_Entities": "Server=localhost;Initial Catalog=YourDBName;User ID=your_username;
Password=your_password;TrustServerCertificate=True;"
"ZnodePublish_Entities": "Server=localhost;Initial Catalog=YourDBName;User ID=your_username;
Password=your_password;TrustServerCertificate=True;"
"ZnodeKlaviyo_Entities": "Server=localhost;Initial Catalog=YourDBName;User ID=your_username;
Password=your_password;TrustServerCertificate=True;",
"ZnodeFramework_Entities": "Server=localhost;Initial Catalog=YourDBName;User ID=your_username;
Password=your_password;TrustServerCertificate=True;",
"HangfireConnection": "Server=localhost;Initial Catalog=YourDBName;User ID=your_username;
Password=your_password;TrustServerCertificate=True;",
"ZnodeRecommendationDB": "Server=localhost;Initial Catalog=YourDBName;User ID=your_username;
Password=your_password;TrustServerCertificate=True;",
"ZnodeRecommendation_Entities": "Server=localhost;Initial Catalog=YourDBName;User ID=your_username;
Password=your_password;TrustServerCertificate=True;"
"ZnodeMongoDBForLog": mongodb://localhost:27017/Znode_Log"
},
Step 6: Run the Project
Once all the above steps are completed, you can run the V1 and V2 API projects. For this, you can either click on the “Start” button or press the “F5” key.
To test the API using Postman, complete the following steps:
- Launch the Postman application.
Open the Postman application on your system. If you haven’t installed it, download it from https://www.postman.com/downloads - Set the environment variables.
You can set environment variables like {{baseUrl}}, {{token}}, etc.
Go to the top right corner → Click Environment → Add new environment variables - Enter the URL and select the appropriate HTTP method(GET, POST, PUT, DELETE, etc).
- Set all the required headers.
Go to the Headers tab and set the required headers - Set the request body and click on the Send button.
Enable Caching
Enable Caching
To improve performance, we need to enable caching in appsettings.json (Redis / SQL, you can allow Redis or SQL-based caching in your application.
- Open appsettings.json of both V1 and V2 API projects.
- Update the Caching Section
- Add or update the following JSON block:
- For Radis Cache.
"Caching": { "Type": "ZnodeRedisCache", // Options: ZnodeRedisCache or ZnodeSqlCache
"AbsoluteExpiration": "30",
"SlidingExpiration": "20",
"SqlCacheConnectionString": "Server=YOUR_SERVER;Database=YOUR_DB;User Id=USERNAME;Password=PASSWORD;TrustServerCertificate=True",
"CacheSchemaName": "dbo",
"CacheTableName": "SQLCache",
"DeletionInterval": "30",
"RedisCacheConnectionString": "localhost:6379",
"RedisCacheInstanceName": "Dev",
"InMemoryCacheKeys": "SiteConfig"
} - For InMemory Cache
"Caching": {
"Type": "InMemory",
"AbsoluteExpiration": "30",
"SlidingExpiration": "20",
"SqlCacheConnectionString": "Server={Your Serve Name};Database={Your Database Name};User Id={Your UserName};Password={Your Password}; TrustServerCertificate=True",
"CacheSchemaName": "dbo",
"CacheTableName": "SQLCache",
"DeletionInterval": "30",
"RedisCacheConnectionString": "{Redis Server Connection string}",
"RedisCacheInstanceName": "Dev",
"InMemoryCacheKeys": "SiteConfig"
},
- For Radis Cache.
- Choose Caching Type
- Use "ZnodeRedisCache" for Redis (recommended for distributed environments).
- Use "ZnodeSqlCache" for SQL Server-based caching.
- Save & Restart Application
- Setting Up RabbitMQ for EventBus:
For enhanced performance, consider enabling Redis or SQL-based caching within your application. While optional, this configuration is highly recommended for environments that mimic production.- Open the appsettings.json file of both the V1 and V2 API projects.
- Update the EventBus Section
- Add or update the following JSON block:
"EventBus": { "MessageBrokerService": "RabbitMQ", // Use "RabbitMQ" to enable it
"ServiceBusConnectionString": "YOUR_SERVICE_BUS_CONN_STRING", // Optional, if using Azure Service Bus
"RabbitMQConnectionString": "amqp://guest:guest@localhost:5672", // Default local connection
"RabbitMQManagementUrl": "http://localhost:15672", // Web UI access
"RabbitMQUserName": "guest",
"RabbitMQPassword": "guest",
"QueueName": "base-cache-queue",
"RetryCount": "2",
"RetryInterval": "200",
"EventRetry": "true"
}
- Add or update the following JSON block:
- Run RabbitMQ Locally
- Make sure RabbitMQ is installed and running on your system. You can use:
- Docker image: rabbitmq: management
- Or install it directly from: https://www.rabbitmq.com/download.html
- Access RabbitMQ Management UI
- Go to http://localhost:15672
- Log in with the default:
- Username: guest
- Password: guest
- Make sure RabbitMQ is installed and running on your system. You can use: