Skip to main content
Version: 0.6.0 (Latest)

📂 Category Route Blocks

Category route blocks provide pre-configured HTTP endpoints for category 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

Category route blocks are designed to:

  • Provide complete API endpoints for category 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 category 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 Category Routes

createCategoryRoute

Creates a new category and returns the created resource.

Purpose: Handles category creation

Route Details:

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

Handlers: createCategory, getCategoryById, normalizeCategoryTerminator

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

Usage:

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

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

getCategoryRoute

Retrieves a specific category by ID with existence validation.

Purpose: Fetches category data with validation

Route Details:

  • Method: GET
  • Path: /categories/:categoryId
  • Authentication: Not required

Handlers: getCategoryById, normalizeCategoryTerminator

Validators: doesCategoryExist

Usage:

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

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

findCategoriesRoute

Retrieves all categories with normalized list format.

Purpose: Lists categories with pagination

Route Details:

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

Handlers: findCategories, normalizeCategoriesListTerminator

Validators: None

Query Parameters

  • description?: string
  • name?: string
  • parent?: string
  • status?: string
  • page?: number
  • limit?: number

Usage:

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

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

updateCategoryRoute

Updates an existing category and returns the updated resource.

Purpose: Modifies category data

Route Details:

  • Method: PATCH
  • Path: /categories/:categoryId
  • Authentication: Required (Bearer token)

Handlers: updateCategory, getCategoryById, normalizeCategoryTerminator

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

Usage:

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

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

deleteCategoryRoute

Deletes a category by ID with existence validation.

Purpose: Removes category

Route Details:

  • Method: DELETE
  • Path: /categories/:categoryId
  • Authentication: Required (Bearer token)

Handlers: deleteCategory, deleteCategoryTerminator

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

Usage:

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

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

enableCategoryRoute

Enables a category by ID with existence validation.

Purpose: Activates category status

Route Details:

  • Method: POST
  • Path: /categories/:categoryId/enable
  • Authentication: Required (Bearer token)

Handlers: enableCategory, enableCategoryTerminator

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

Usage:

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

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

disableCategoryRoute

Disables a category by ID with existence validation.

Purpose: Deactivates category status

Route Details:

  • Method: POST
  • Path: /categories/:categoryId/disable
  • Authentication: Required (Bearer token)

Handlers: disableCategory, disableCategoryTerminator

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

Usage:

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

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