Performance: API resource classes
MEDIUM IMPACT
API resource classes affect the server response time and the size of JSON payloads sent to the client, impacting page load speed and interaction responsiveness.
return new UserResource($user);return response()->json($user->toArray());| Pattern | Payload Size | Server CPU | Network Transfer | Verdict |
|---|---|---|---|---|
| Raw Model to JSON | Large (all attributes) | High (full serialization) | High (large JSON) | [X] Bad |
| API Resource Class | Small (selected fields) | Low (optimized serialization) | Low (smaller JSON) | [OK] Good |