Public
HTTP
- thisUrl@wiltProgrammatically get the API URLs for the val that calls this val. For example: // @wilt.myCoolVal: const myCoolVal = @wilt.thisUrl("web"); } // returns: // https://wilt-myCoolVal.web.val.run If targetVal is passed as entry , returns the URL of the very first val in the current call stack. For example: // @wilt.myFirstCoolVal: const myFirstCoolVal = @wilt.mySecondCoolVal()); } // @wilt.mySecondCoolVal: const mySecondCoolVal = () => { return @wilt.thisUrl("web", "entry"); } // Running @wilt.myFirstCoolVal returns: // https://wilt-myFirstCoolVal.web.val.runScript
- fetch@stdProxied fetch - Docs ↗ The Javascript Fetch API is directly available within a Val. However sometimes fetch calls are blocked by the receiving server for using particular IP addresses. Additionally, network blips or unreliable web services may lead to failures if not handled properly. The Val Town standard library contains an alternative version, std/fetch , that wraps the JavaScript Fetch API to provide additional functionality. The fetch function from std/fetch reroutes requests using a proxy vendor so that requests obtain different IP addresses. It also automatically retries failed requests several times. Note that using std/fetch will be significantly slower than directly calling the Javascript Fetch API due to extra network hops. Usage After importing std/fetch , the fetch method is used with the same signature as the Javascript Fetch API. import { fetch } from "https://esm.town/v/std/fetch"; let result = await fetch("https://api64.ipify.org?format=json"); let json = await result.json(); console.log(json.ip); If you run the above code multiple times, you'll see that it returns different IP addresses, because std/fetch uses proxies so that each request is made from a different IP address. 📝 Edit docsScript
January 1, 2024