Overview
TheApiTesting component provides a developer-focused interface for testing protected API endpoints in Cat Web. It demonstrates API integration, displays available containers, and allows testing of authenticated API calls with visual feedback.
Source: src/components/ApiTesting.tsx
Key Features
- Test protected API endpoints with authentication
- Load and display containers from the API
- Interactive UI with buttons and dropdowns
- Toast notifications for success and error states
- Integration with custom
useApiServicehook - Auth0 authentication awareness
Props
This component does not accept any props.State Management
The component manages container data with React state:Container Type
Containers are typed with the following structure:API Integration
The component uses theuseApiService custom hook for API operations:
Loading Containers
Containers are loaded automatically when the user is authenticated:Testing Protected API
The component provides a button to test protected API endpoints:User Interface
The component renders a simple testing interface with two main sections:API Testing Button
- Calls the
getPhoneNumbers()API method - Logs the response to the console
- Shows a success toast notification
- Shows an error toast if the call fails
Container Dropdown
When containers are loaded, a dropdown appears:Material-UI Components
The component uses several Material-UI components:Box: Container for layout and spacingButton: Triggers API testingFormControl: Wrapper for form inputsInputLabel: Label for the select dropdownSelect: Dropdown menu for containersMenuItem: Individual dropdown options
Toast Notifications
The component usesreact-toastify for user feedback:
Required Setup
Ensure you have configured the ToastContainer in your app:Usage Examples
Basic Usage in Routes
Protected Route with AuthGuard
Development Access
Add a navigation link in your layout:Complete Source Code
API Service Hook
The component depends on theuseApiService hook which should provide:
- Authentication token management
- API endpoint configuration
- Request/response handling
- Error handling
Best Practices
- Developer Tool: This component is intended for development and testing purposes
- Authentication Required: Always use behind authentication (AuthGuard)
- Error Handling: Use try-catch blocks for all API calls
- User Feedback: Provide toast notifications for all user actions
- Console Logging: Keep console logs for debugging API responses
- Loading States: Consider adding loading indicators for async operations
Extending the Component
Adding More API Tests
Adding Loading State
Related Components
- MasterLayout Component - Navigation includes link to API tests
- AuthGuard Component - Protects this component from unauthenticated access
Related Hooks
useApiService- Custom hook for API operationsuseAuth0- Auth0 authentication hook
