API References
This section contains detailed API references, including endpoints, methods, and parameters.
Module
- Path:
/vendor/msamgan/lact/resources/actions/
- Dependencies:
throwException
baseHeaders
makeErrorObject
loadValidationErrors
validationStatusErrorCode
route
Properties
errors
- Type:
Object
- Description: Stores errors returned from the server after the request is made.
routeName
- Type:
string
- Value:
'name.of.the.route'
- Description: Name of the route used for fetching data.
Methods
1. call({ params, headers, methodHead })
Executes a request to the named
route.
-
Parameters:
params
(optional): An object of query parameters to append to the route.headers
(optional): An object of HTTP headers to include in the request.methodHead
(optional, defaultfalse
): Iftrue
, the request will use theHEAD
method; otherwise, it will useGET
.
-
Returns:
- A
Promise
that resolves to theresponse
.
- A
-
Behavior:
- Sends a
GET
orHEAD
request to thenamed
route. - Populates the
errors
property with errors from the server. - Invokes
throwException
on theresponse
if there is non20*
response.
- Sends a
Example:
functionName
.call({
params: { userId: 1 },
headers: { Authorization: 'Bearer token' }
}).then(response => { console.log(response); });
2. data({ params, headers })
Executes a GET
request to retrieve data.
-
Parameters:
params
(optional): An object of query parameters to append to the route.headers
(optional): An object of HTTP headers to include in the request.
-
Returns:
- A
Promise
that resolves to the parsed JSONresponse
.
- A
-
Behavior:
- Sends a
GET
request to thenamed
route. - Populates the
errors
property with errors from the server. - Invokes
throwException
on theresponse
if there is non20*
response.
- Sends a
Example:
functionName
.data({
params: { userId: 1 },
headers: { Authorization: 'Bearer token' }
}).then(data => { console.log(data); });
3. route(params)
Generates a URL for the named
route.
-
Parameters:
params
(optional): An object of query parameters to append to the route.
-
Returns:
- The fully constructed route URL as a string.
Example:
const url = functionName.route({ userId: 1 });
console.log(url); // Outputs the URL
4. form(params)
Creates an object for form submission to the named
route.
-
Parameters:
params
(optional): An object of query parameters to append to the route.
-
Returns:
- An object containing:
method
: The HTTP method for the form based on the declaration.url
: The generated URL for thenamed
route.
- An object containing:
Example:
// used with inertia form.
const formInfo = functionName.form({ userId: 1 });
console.log(formInfo); // Output: { method: '...', url: '...' }