Skip to content

Latest commit

 

History

History

node-api-only

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

Node.js API-Only Example

A minimal Express-style HTTP server using DiscountKit adapters without React.

Features

  • REST API for discount management
  • Multi-platform support (Shopify + BigCommerce)
  • Capability validation endpoint
  • Cross-platform discount sync

Setup

From the monorepo root:

pnpm install
pnpm build

Then:

cd examples/node-api-only
pnpm dev

Server starts on http://localhost:3001.

API Endpoints

POST /discounts

Create a discount on a specific platform.

curl -X POST http://localhost:3001/discounts \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "shopify",
    "incentive": {
      "title": "Test 10%",
      "value": { "type": "percentage", "percentage": 0.1 },
      "code": { "type": "static", "code": "TEST10" }
    }
  }'

POST /validate

Validate an incentive against a platform.

curl -X POST http://localhost:3001/validate \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "bigcommerce",
    "incentive": {
      "title": "BXGY Test",
      "value": { "type": "bxgy", "customerBuys": {...}, "customerGets": {...} }
    }
  }'

POST /sync

Create the same discount across multiple platforms.

curl -X POST http://localhost:3001/sync \
  -H "Content-Type: application/json" \
  -d '{
    "platforms": ["shopify", "bigcommerce"],
    "incentive": {
      "title": "Cross-Platform 15%",
      "value": { "type": "percentage", "percentage": 0.15 },
      "code": { "type": "static", "code": "CROSS15" }
    }
  }'

How It Works

This example demonstrates using DiscountKit adapters in a server-side context without any React dependencies. It uses Node.js built-in http module (no Express) to keep dependencies minimal.