Skip to main content

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

HeaderValueRequired
Content-Typeapplication/jsonYes
Acceptapplication/jsonYes
AuthorizationBearer YOUR_API_TOKENYes

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

  1. Request Reception: The server receives the GET request at the /api/widget-data endpoint.
  2. Authentication Check: The server verifies the Bearer token in the request headers to ensure the user is authenticated.
  3. Parameter Validation: The server checks for the presence of the type parameter and validates it against allowed values.
  4. Data Retrieval: Based on the validated type, the server fetches the corresponding data from the database.
  5. Response Formatting: The server formats the response using the WidgetDataResource class, including success and error messages.
  6. 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.