Can I use Spwig with a headless frontend like Next.js?

Hello,

I am a developer and I want to build a custom storefront using Next.js. Does Spwig have a headless API or SDK that I can use?

Specifically I need:

  • Product catalog API
  • Cart management
  • Checkout flow
  • Order webhooks

Is this possible with Spwig? Any documentation links would be great.

Thanks!

Yes, you can absolutely use Spwig with a headless frontend like Next.js! Spwig is designed with a headless architecture, which means you can build a custom storefront using a frontend framework like Next.js and interact with Spwig’s backend via its APIs and SDKs.

Here’s how you can achieve the specific features you mentioned:


:white_check_mark: Product Catalog API

You can fetch product data using the Spwig Shop API, which is accessible at the /api endpoint of your Spwig installation. For example:

GET /api/products

This will return a list of products. You can also filter, sort, and paginate using query parameters.


:white_check_mark: Cart Management

Spwig provides endpoints for managing the cart, such as:

  • Add item to cart:

    POST /api/cart/items
    Payload:
    {
      "product_id": 123,
      "quantity": 1
    }
    
  • Get current cart:

    GET /api/cart
    
  • Update cart item:

    PUT /api/cart/items/{item_id}
    
  • Remove item from cart:

    DELETE /api/cart/items/{item_id}
    

:white_check_mark: Checkout Flow

The checkout process is handled through the Spwig backend, but you can trigger it from your Next.js frontend using the /api/checkout endpoint. You’ll need to provide customer and payment information as part of the request.

Example:

POST /api/checkout
Payload:
{
  "customer": {
    "email": "[email protected]",
    "first_name": "John",
    "last_name": "Doe"
  },
  "payment_method": "credit_card",
  "payment_data": {
    "card_number": "4111111111111111",
    "exp_month": "12",
    "exp_year": "2025",
    "cvv": "123"
  }
}

:white_check_mark: Order Webhooks

Spwig supports webhooks for order events. You can set up your Next.js app to receive these events by configuring a webhook endpoint in your Spwig admin panel.

Example webhook event:

POST /webhooks/orders
Content-Type: application/json
{
  "event": "order.created",
  "data": {
    "order_id": "12345",
    "status": "completed"
  }
}

:books: Additional Resources

  • Next.js App Router Example – Complete examples for building a headless Spwig storefront with Next.js 14+.
  • Image Optimization – Learn how to use next/image for optimized image loading from Spwig’s backend.
  • Rate Limits – Understand how to handle rate limits in your frontend.

:hammer_and_wrench: Nginx Routing

If you’re deploying your Next.js app alongside Spwig, you can use the provided Nginx configuration to route traffic appropriately. For example:

location /api/ {
    proxy_pass http://shop-backend:8445;
}

This will proxy API requests to the Spwig backend.


Let me know if you need help setting up the actual Next.js project or integrating with the Spwig APIs!


Spwig AI Support — docs.spwig.com | community.spwig.com