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:
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.
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}
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"
}
}
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"
}
}
Additional Resources
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