This is an example call of @stevekrouse/insecureFetch

Readme
1
2
3
4
5
6
import { insecureFetch } from "https://esm.town/v/stevekrouse/insecureFetch";
const url = "https://assignment-api.uspto.gov/patent/basicSearch?query=1234567&fields=main&rows=20";
const data = await insecureFetch(url);
const text = await data.text();
console.log(text);
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.
Comments
easrng avatar

Cloudflare workers doesn't validate https certs???

stevekrouse avatar

Apparently not!

vladimyr avatar

I assume it supports only GET requests?

stevekrouse avatar

I think it's a pretty naive proxy that supports anything, why do you ask, @vladimyr?

vladimyr avatar

I didn't have any particular use case in mind just curious to know what to write next to it in my notes :)

vladimyr avatar

And to answer my question, no POST requests aren't supported:

$ curl -s 'https://pie.dev/post' -F'foo=bar' # works
$ curl -s 'https://unsecure-fetch.val-town.workers.dev?url=https://pie.dev/post' -F'foo=bar' # returns 405 Method Not Allowed
vladimyr avatar

Also, keep in mind that you need to URL encode url param:

$ curl -s 'https://unsecure-fetch.val-town.workers.dev?url=https://pie.dev/get?foo=bar&baz=42' | jq -c '.args'
# ==> {"foo":"bar"}
$ curl -s 'https://unsecure-fetch.val-town.workers.dev?url=https%3A%2F%2Fpie.dev%2Fget%3Ffoo%3Dbar%26baz%3D42' | jq -c '.args'
# ==> {"baz":"42","foo":"bar"}

In @stevekrouse's example: https://unsecure-fetch.val-town.workers.dev?url=https://assignment-api.uspto.gov/patent/basicSearch?query=1234567&fields=main&rows=20 query is consumed by proxied URL but fieldsand rows get consumed by proxy instead ⚠️

stevekrouse avatar

It should now support POST requests and everything else – it forwards the whole req with the url changed.

I also made a helper method: @stevekrouse/insecureFetch

And include the source on the fetch's homepage: https://unsecure-fetch.val-town.workers.dev/