Alternative to Fetch API (can't add body to GET)
Is there an alternative to the Fetch API within a Cloudflare worker? Axios does not work (as it relies on Node libs) .. I assume other packages will have a similar problem. Reason is because a vendor API requires a body on a GET request and that produces a "TypeError: Request with a GET or HEAD method cannot have a body". At this point I am considering proxying the request via an AWS Lambda but would love a workaround within a the Cloudflare environment.
2 Replies
An alternative would just use the fetch API anyway. You could send over TCP and craft your own HTTP/1.1 request
Thanks for your response. I had a play with the TCP sockets runtime API and was able to do some basic stuff, just receive a HTTPS response from a GET request using HTTP 1.0 (auto closed connection) - 1.1 would not close. Beyond that it started to get trickier than the time I have available.. as much as I enjoy the challenge, with limited time I opted for the lambda approach since I already have one in action.