5.0.0 • Published 9 months ago
@aging/rest-path v5.0.0
rest-path
Class: RestPath
- This class provides a helper method to dynamically generate RESTful API paths for a specific database entity. It is intended to simplify the creation and management of endpoints for CRUD (Create, Read, Update, Delete) operations and other entity-specific routes by following REST conventions.
Features:
- Path Generation: Automatically constructs API paths for various operations such as retrieving, creating, updating, and deleting resources based on the entity's base URL.
- Consistency: Ensures uniform and predictable API paths across the application.
- Customization: Allows for the definition of custom routes or variations in paths for specific actions.
Usage:
import { RestPath } from '@aging/rest-path';
const S = new RestPath({ name: 'sample', pluralName: 'samples', prefix: '' });
S.PREFIX; // Output: ''
S.ID_PATH; // Output: /sample/:id
S.INCREMENT_PATH; // Output: /sample/:id
S.SINGULAR_PATH; // Output: /sample
S.PLURAL_PATH; // Output: /samples
S.RELATION_PATH; // Output: /sample/:id/:rn/:rid
S.UNSET_RELATION_PATH; // Output: /sample/:id/:rn
S.COUNT_PATH; // Output: /sample
Benefits:
- Scalability: As the number of entities in your application grows, managing API routes becomes easier with a centralized, reusable approach.
- Maintainability: Reduces redundancy and potential for errors in hardcoded paths.
- Flexibility: Adaptable to different naming conventions or route structures.