API Endpoints
Overview
The DataForge package provides 7 powerful API endpoints to handle various web service requirements. These endpoints cover data retrieval, manipulation, and integration needs, making them suitable for applications ranging from small-scale systems to enterprise-grade platforms.
1. api/list
Description:
Fetches a paginated list of records from a specified SQL class and method.
Endpoint Format:
/api/list/{sql_class_name}:{sql_class_method}?select={select_type}&page={page_number}&limit={record_limit}&keyword={search_keyword}&sort={sort_field}&order={sort_order}
Key Features:
- Supports pagination using
page
andlimit
. - Provides total count of matched records.
- Applies dynamic filters and sorting.
Sample Request:
/api/list/Product:list?page=2&limit=5&sort=id&order=desc
2. api/all
Description:
Fetches all matched records from a specified SQL class and method. Similar to api/list
but without pagination.
Endpoint Format:
/api/all/{sql_class_name}:{sql_class_method}?select={select_type}&limit={record_limit}&keyword={search_keyword}
Key Features:
- Fetches all or limited records using the
limit
parameter. - Ideal for dropdowns and complete lists.
Sample Request:
/api/all/Category:list
/api/all/Category:list?select=dropdown-option&limit=7
3. api/item
Description:
Fetches the first matched record from a specified SQL class and method.
Endpoint Format:
/api/item/{sql_class_name}:{sql_class_method}?select={select_type}&keyword={search_keyword}
Key Features:
- Returns a single record as a JSON object.
- Supports filters similar to
api/list
.
Sample Request:
/api/item/Product:list
/api/item/Product:list?category_id=4&select=entity
/api/item/Product:list?id=17&select=item
4. api/field
Description:
Fetches the first column value from the first matched record of a specified SQL class and method.
Endpoint Format:
/api/field/{sql_class_name}:{sql_class_method}?select={select_type}&keyword={search_keyword}
Key Features:
- Ideal for fetching single values (e.g., totals, sums, or aggregates).
Sample Request:
/api/field/Product:list?select=total
/api/field/Product:list?category_id=6&select=total
/api/field/Sales:Summary?select=total_products
/api/field/Sales:Summary?select=total_quantity
/api/field/Sales:Summary?select=total_amount
/api/field/Sales:Summary?select=average_price
5. api/entity
Description:
Fetches an entity's base properties, relationships, or grouped attributes.
Endpoint Format:
/api/entity/{entity_name}/{id}?attrib={attribute_name}&attribGroup={group_name}&skipBaseAttrib={0|1}
Key Features:
- Retrieves entity base properties (via
init
method). - Supports lazy-loaded attributes and attribute groups.
- Optionally skips base attributes.
Sample Requests:
- Fetch base properties:
/api/entity/Product/1234
Fetch with related attribute:
/api/entity/Product/1234?attrib=Category
Fetch with attribute group:
/api/entity/Product/1234?group=Details
- Fetch attribute group only:
/api/entity/Product/1234?group=Details&baseAttrib=0
6. api/task
Description:
Executes Task methods for custom actions like Save, Update, Delete, or complex data preparation.
Endpoint Format:
/api/task/{Task class name}/{Task Method}
Key Features:
- Combines SQL and Entity operations for complex workflows.
- Handles custom actions beyond standard CRUD.
Sample Request:
/api/task/Invoice/detail?invoiceId=1234
7. api/guest-task
Description:
Allows unauthenticated access to Task methods with a guest
prefix in their names.
Endpoint Format:
/api/guest-task/{Task class name}/{Task Method}
Key Features:
- Provides limited access for guest users.
- Ensures sensitive data remains secure.
Sample Request:
/api/guest-task/Invoice/detail?productId=1234
Key Strengths
1. Versatility
- Supports a wide range of use cases: pagination (
api/list
), full data retrieval (api/all
), single records (api/item
), aggregates (api/field
), and workflows (api/Task
,api/GuestTask
).
2. Scalability
- Efficient for small to large-scale applications.
- Modular Task and Entity methods ensure seamless expansion.
3. Flexibility
- Customizable filters, sorting, and workflows.
- Easily integrates with various frontends or third-party services.
4. Security
- Clear distinction between authenticated and guest endpoints.
- Controlled data exposure with
api/GuestTask
.
5. Performance Optimization
- Lazy loading of entity attributes.
- Dynamic filtering minimizes data overhead.
Conclusion
These 7 API endpoints form a comprehensive framework for handling diverse data needs, ensuring a balance of performance, flexibility, and security. With their streamlined design and powerful features, they enable developers to create scalable and maintainable web services effortlessly.