Skip to main content
Version: 0.6.0 (Latest)

📦 Product Route Blocks

Product route blocks provide pre-configured HTTP endpoints for product management operations in Nodeblocks applications. These routes combine handlers, validators, and middleware to create complete API endpoints with proper authentication, authorization, and error handling.


🎯 Overview

Product route blocks are designed to:

  • Provide complete API endpoints for product management operations
  • Combine handlers with validators for secure operations
  • Include authentication and authorization checks
  • Support functional composition patterns
  • Handle logging and error management automatically

📋 Route Structure

Each product route follows a consistent pattern:

  • HTTP Method: Defines the operation type (GET, POST, PATCH, DELETE)
  • Path: Specifies the endpoint URL with parameters
  • Handler: Composed function chain for business logic
  • Validators: Authentication and authorization checks

🔧 Available Product Routes

createProductRoute

Creates a new product and returns the created resource.

Purpose: Handles product creation with full resource retrieval

Route Details:

  • Method: POST
  • Path: /products
  • Authentication: Required (Bearer token)

Handlers: createProduct, getProductById, normalizeProductTerminator

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.createProductRoute);

findProductsRoute

Retrieves all products with normalized list format.

Purpose: Lists products with pagination

Route Details:

  • Method: GET
  • Path: /products
  • Authentication: Not required

Handlers: findProducts, normalizeProductsListTerminator

Validators: None

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.findProductsRoute);

createProductBatchRoute

Creates multiple products in batch and returns the created resources.

Purpose: Handles batch product creation

Route Details:

  • Method: POST
  • Path: /products/batch
  • Authentication: Required (Bearer token)

Handlers: createProductBatch, getProductsByIds, normalizeProductsListTerminator

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.createProductBatchRoute);

updateProductBatchRoute

Updates multiple products in batch and returns the updated resources.

Purpose: Handles batch product updates

Route Details:

  • Method: PATCH
  • Path: /products/batch
  • Authentication: Required (Bearer token)

Handlers: updateProductBatch, getProductsByIds, normalizeProductsListTerminator

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.updateProductBatchRoute);

deleteProductBatchRoute

Deletes multiple products in batch.

Purpose: Handles batch product deletion

Route Details:

  • Method: DELETE
  • Path: /products/batch
  • Authentication: Required (Bearer token)

Handlers: deleteProductBatch, deleteBatchProductsTerminator

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.deleteProductBatchRoute);

getProductRoute

Retrieves a specific product by ID.

Purpose: Fetches product data

Route Details:

  • Method: GET
  • Path: /products/:productId
  • Authentication: Not required

Handlers: getProductById, normalizeProductTerminator

Validators: None

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.getProductRoute);

updateProductRoute

Updates an existing product and returns the updated resource.

Purpose: Modifies product data with access control

Route Details:

  • Method: PATCH
  • Path: /products/:productId
  • Authentication: Required (Bearer token)

Handlers: updateProduct, getProductById, normalizeProductTerminator

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.updateProductRoute);

deleteProductRoute

Deletes a product by ID.

Purpose: Removes product with access control

Route Details:

  • Method: DELETE
  • Path: /products/:productId
  • Authentication: Required (Bearer token)

Handlers: deleteProduct, deleteProductTerminator

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.deleteProductRoute);

copyProductRoute

Creates a copy of an existing product.

Purpose: Duplicates product with access control

Route Details:

  • Method: POST
  • Path: /products/:productId/copy
  • Authentication: Required (Bearer token)

Handlers: copyProduct, getProductById, normalizeProductTerminator

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.copyProductRoute);

copyProductBatchRoute

Creates copies of multiple products in batch.

Purpose: Handles batch product copying

Route Details:

  • Method: POST
  • Path: /products/batch/copy
  • Authentication: Required (Bearer token)

Handlers: copyProductBatch, getProductsByIds, normalizeProductsListTerminator

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.copyProductBatchRoute);

getProductImageUploadUrlRoute

Generates a signed URL to upload a product image via GET /products/:productId/image-upload-url.

Purpose: Issues a pre-signed URL for secure product image uploads

Route Details:

  • Method: GET
  • Path: /products/:productId/image-upload-url
  • Authentication: Required (Bearer token)

Blocks: generateProductImageUploadUrl Terminators: Built-in success/error mapping via orThrow

Validators: isAuthenticated, checkIdentityType(['admin'])

Usage:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.getProductImageUploadUrlRoute);