AgentSkillsCN

Api Debug

API 调试

SKILL.md

API Debug Skill

Test NearBlocks API endpoints using curl.

Usage

bash
/api-debug [test-type]

Test types:

  • holders - Test NFT holders endpoint (default)
  • health - Check API health
  • all - Run all tests

Implementation

When invoked:

Test 1: API Health Check

bash
curl -i -w "\nTime: %{time_total}s\n" \
  "http://localhost:3000/api/nearblocks/nfts/nearlegion.nfts.tg/holders?per_page=1"

Display:

  • Status code
  • Response time
  • Rate limit headers (if present)
  • First holder data

Test 2: Holders Endpoint (Full)

bash
curl -s -w "\nTime: %{time_total}s\n" \
  "http://localhost:3000/api/nearblocks/nfts/nearlegion.nfts.tg/holders?per_page=50&page=1"

Display:

  • Number of holders returned
  • Response time
  • Sample of first 3 holders
  • Pagination info

Test 3: Both Contracts

Run holders query for both Legion and Initiate contracts in parallel:

bash
# Legion
curl -s "http://localhost:3000/api/nearblocks/nfts/nearlegion.nfts.tg/holders?per_page=50" &

# Initiate
curl -s "http://localhost:3000/api/nearblocks/nfts/initiate.nearlegion.near/holders?per_page=50" &

wait

Compare response times and data quality.

Test 4: Rate Limit Testing

Make 5 rapid requests and monitor for 429 responses:

bash
for i in {1..5}; do
  echo "Request $i:"
  curl -i "http://localhost:3000/api/nearblocks/nfts/nearlegion.nfts.tg/holders?per_page=1" \
    2>&1 | grep -E "HTTP|X-RateLimit|Retry-After"
  sleep 0.5
done

Output Format

code
=== NearBlocks API Debug ===

[Test 1: Health Check]
✓ Status: 200 OK
✓ Response time: 234ms
✓ Returns valid JSON

[Test 2: Legion Holders]
✓ Endpoint: /api/nearblocks/nfts/nearlegion.nfts.tg/holders
✓ Status: 200 OK
✓ Response time: 189ms
✓ Holders returned: 50
✓ Sample: bob.near, alice.near, charlie.near

[Test 3: Initiate Holders]
✓ Endpoint: /api/nearblocks/nfts/initiate.nearlegion.near/holders
✓ Status: 200 OK
✓ Response time: 156ms
✓ Holders returned: 50

[Test 4: Rate Limits]
Request 1: 200 OK
Request 2: 200 OK
Request 3: 200 OK
Request 4: 200 OK
Request 5: 200 OK
✓ No rate limiting detected

Summary:
- All endpoints responding normally
- Average response time: 193ms
- No rate limit issues

Error Scenarios

Handle and report:

  • 000: Connection failed (dev server not running)
  • 404: Contract not found or invalid endpoint
  • 429: Rate limit exceeded
  • 500: API server error
  • Timeout: Request took >10s

Critical Files Reference

Read these for context:

  • /Users/jlwaugh/Desktop/legionary/src/constants.ts - Contract IDs, API config
  • /Users/jlwaugh/Desktop/legionary/src/hooks/useLegionMembers.ts - API usage patterns
  • /Users/jlwaugh/Desktop/legionary/src/types/nearblocks.ts - Response structure