Please provide code that connects a frontend component to a RESTful API. I need a complete implementation that handles API requests, loading states, and error handling effectively.
DETAILS:
- Frontend Framework: [FRAMEWORK]
- Component Purpose: [COMPONENT_PURPOSE]
- API Endpoint: [API_ENDPOINT]
- Request Type: [REQUEST_TYPE]
- Authentication Method: [AUTH_METHOD]
- Request Data: [REQUEST_DATA]
- Expected Response: [RESPONSE_STRUCTURE]
REQUIREMENTS:
- Create a component that connects to the specified API
- Handle the authentication requirements
- Implement loading indicators during API calls
- Process successful responses properly
- Provide comprehensive error handling
- Follow best practices for the chosen framework
- Ensure clean, maintainable code
Please include:
1. COMPONENT CODE
- Complete implementation of the component
- State management for data, loading, and errors
- UI elements for different states
- User interaction handling
2. API CONNECTION
- API request configuration
- Authentication implementation
- Response handling
- Error processing
3. CODE ORGANIZATION
- Proper structure and separation of concerns
- Reusable patterns if applicable
- Clear naming and organization
4. EXPLANATION
- Overview of the implementation approach
- Key decisions and best practices
- Any alternatives or optimizations
- Important considerations
Please ensure the code is production-ready, following current best practices for the specified frontend framework.