Widget Data
This document describes the endpoint for retrieving widget data.
Get Widget Data
Endpoint
- Method: GET
- URL:
/api/widget-data
Description
Retrieves data for the widgets used in the application.
Request Headers
| Header | Value | Required |
|---|---|---|
| Content-Type | application/json | Yes |
| Accept | application/json | Yes |
| Authorization | Bearer YOUR_API_TOKEN | Yes |
Response Formats
Success Response
{
"success": true,
"message": "Widget data retrieved successfully.",
"data": {
"widgets": [
{
"intention": "Some Intention",
"title": "Affirmation Title",
"text": "This is the affirmation text."
}
]
}
}
Error Response
{
"success": false,
"message": "Error message",
"status_code": 400
}
Error Types
Invalid Type
{
"success": false,
"message": "Invalid type",
"status_code": 400
}
Unauthorized
{
"success": false,
"message": "Unauthorized",
"status_code": 401
}
Example Implementation Flow
- Request Reception: The server receives the GET request at the
/api/widget-dataendpoint. - Authentication Check: The server verifies the Bearer token in the request headers to ensure the user is authenticated.
- Parameter Validation: The server checks for the presence of the
typeparameter and validates it against allowed values. - Data Retrieval: Based on the validated
type, the server fetches the corresponding data from the database. - Response Formatting: The server formats the response using the
WidgetDataResourceclass, including success and error messages. - Response Sending: The server sends the formatted response back to the client.
Implementation Notes
- This endpoint retrieves all the necessary data to render the widgets on the client side.
- Ensure proper authentication is handled to secure the endpoint.