Skip to content

refactor: parse JSON responses via Response.json() instead of manual JSON.parse - #22

Merged
joeykamsteeg merged 2 commits into
developfrom
feature/response-json-parser
Aug 4, 2026
Merged

joeykamsteeg merged 2 commits into
developfrom
feature/response-json-parser

Conversation

@joeykamsteeg

Copy link
Copy Markdown
Member

Summary

  • performRequest now calls Response.json() directly for JSON responses that don't need to be cached, instead of manually reading text and calling JSON.parse on it (reviewer feedback on the beforeRequest hook PR).
  • The GET + cache-configured path is unchanged: it still reads the body as text once, since that raw text is also persisted to the cache entry.
  • No change to the public API, FetchifyResponse shape, or cache entry format — data, response, and cached behave identically to before.

Test plan

  • bun test — 199 pass, 0 fail
  • bun run lint — clean
  • Added a test covering a cached JSON GET: confirms data still parses correctly and the cache adapter receives the exact raw text body
  • Existing tests already cover the non-cached JSON-parse and invalid-JSON-yields-null-data scenarios on the new Response.json() path

🤖 Generated with Claude Code

…JSON.parse

Response.json() already parses JSON and rejects on invalid input, so the
manual text()+JSON.parse() step is unnecessary except on the GET+cache path,
where the raw text is still needed for the cache entry.
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

test: Run #37

Tests 📝 Passed ✅ Failed ❌ Skipped ⏭️ Duration ⏱️
199 199 0 0 292ms

🎉 All tests passed!

Github Test Reporter by CTRF 💚

@joeykamsteeg
joeykamsteeg merged commit 072705a into develop Aug 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant