import { IHttpResponse, IObject } from "@/types/interface"; import http from…
- User
import { IHttpResponse, IObject } from "@/types/interface"; import http from "../utils/http"; // Assuming http is a function that takes a config object and returns a Promise
/**
baseServiceprovides a standardized interface for common CRUD operations- by wrapping the core
httputility. It ensures consistent request configuration - and handles Promise outcomes for various HTTP methods.
/
export default {
/*
- Performs a DELETE HTTP request.
- While DELETE typically uses path parameters, this method allows for an optional
- request body (
data), commonly used for batch deletion (e.g., an array of IDs). - @param path The API endpoint path (e.g., '/api/users/1' or '/api/users/batch').
- @param data Optional request body for the DELETE request (e.g., an array of IDs for batch delete).
- @param headers Optional custom HTTP headers to merge with default headers.
- @returns A Promise that resolves with the HTTP response or rejects with an error. */ delete(path: string, data?: IObject | any[], headers?: IObject): Promise { return http({ url: path, data: data, // Used as request body, often for batch deletes. Be mindful of backend support. method: "DELETE", headers: { // Explicitly setting Content-Type for DELETE if a body is expected. // This ensures consistency across methods that send data. "Content-Type": "application/json;charset=UTF-8", ...headers } }); },
/**
- Performs a GET HTTP request.
- Used for fetching resources. Parameters are sent as URL query strings.
- @param path The API endpoint path.
- @param params Optional query parameters (e.g.,
{ userId: 1, status: 'active' }). - @param headers Optional custom HTTP headers.
- @returns A Promise that resolves with the HTTP response or rejects with an error.
*/
get(path: string, params?: IObject, headers?: IObject): Promise {
// Direct Promise return: The
httputility is expected to return a Promise. // Removed the manual Promise creation and the specificif (error !== "-999")check. // Error handling (like ignoring specific error codes) should ideally be handled // at a lower level within thehttputility's interceptors for consistency. return http({ url: path, params, // Query parameters for GET requests headers, method: "GET" }); },
/**
- Performs a PUT HTTP request.
- Typically used for full updates of existing resources. The request body contains the full resource representation.
- Assistant