PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.9
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.9
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / .agent / rules / api-patterns.md

api-patterns.md in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.4.9, at .agent/rules/api-patterns.md

39 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 # API & Data Management
2
3 ## API Refactoring Patterns
4 - Extract API logic into pure functions that return Promises
5 - Implement caching with search parameters as cache keys
6 - Fix pagination by calculating page numbers based on `startIndex` and `stopIndex`
7
8 ## Centralized API Requests
9 - Create `makeApiRequest()` static functions in Helper class
10 - Include standard headers: site URL and API key
11 - Maintain consistent API request patterns across the application
12
13 ## Race Condition Prevention
14 - Use `AbortController` to cancel previous ongoing requests
15 - Cancel ongoing requests before initiating new requests
16 - Implement proper cleanup in component unmounting
17
18 ## Development API Configuration
19 - Use `TEMPLATELY_DEV_API` constant for API endpoint selection
20 - Simple boolean logic: `true` = dev server, `false`/`undefined` = live API
21 - Avoid complex state tracking for API endpoint management
22
23 ## Error Handling in Async Functions
24 - Throw errors instead of returning them in async functions and promises
25 - This allows calling code to properly catch errors with `.catch()`
26 - Follow JavaScript/Promise best practices for error propagation
27
28 ---
29
30 # Gateway Timeout Handling
31
32 ## Polling Implementation
33 - Implement polling mechanism for 504 Gateway Timeout errors
34 - Use appropriate intervals between polling attempts
35 - Respect `AbortSignal` and clear intervals on component exit
36 - Implement sequential calls with delays between them
37 - Avoid fixed intervals; use dynamic timing based on response
38 - Implement proper cleanup and cancellation
39