data icon indicating copy to clipboard operation
data copied to clipboard

feat: configurable Fetch parsers

Open runspired opened this issue 7 months ago • 0 comments

This PR

  • enables per-handler and per-request tailoring of how the Fetch handler will parse the response text
  • adds default handlers for text/xml/html in addition to json
  • changes Fetch to attempt to use the best parser instead of always assuming json

Open questions:

  • What do pluggable streaming parsers look like?

json streaming formats like ndjson, jsonl, json-seq and ccdj can likely incrementally parse the response. Some formats can likely do a streaming parse without text decoding.

  • Should this just be some utils?

we could produce a series of fetch-handler utils to aide construction of this sort of handler instead.

  • Is there a better pattern for this overall?

The Fetch handler offers broad utility beyond its JSON parse, but maybe there's a better way to surface that utility.

  • What about Errors parsing?

This approach still assumes a json parse of errors falling back to simple body-as-string.

  • Should xml2json be a default parser?

It has a lot of utility especially for ML and is rather easy and small to achieve.

  • What about transforming uploads?

Currently fetch does not handle adding a body to the request, probably should not begin doing so here .... but ... if no body is present we could introduce auto-serialization of the data property. In which case we'd want serialization utils here.

runspired avatar May 21 '25 04:05 runspired