3The Javascript [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/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.
4
5The Val Town standard library contains an alternative version, [`std/fetch`](https://www.val.town/v/std/fetch), that wraps the JavaScript Fetch API to provide additional functionality. The fetch function from [`std/fetch`](https://www.val.town/v/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`](https://www.val.town/v/std/fetch) will be significantly slower than directly calling the Javascript Fetch API due to extra network hops.
6
7## Usage
171. [Generate your keypair](https://www.val.town/embed/new?code=import+%7B+set+%7D+from+%22https%3A%2F%2Fesm.town%2Fv%2Fstd%2Fset%22%3B%0Aimport+%7B+generateKeys+%7D+from+%22https%3A%2F%2Fesm.town%2Fv%2Fstevekrouse%2FgenerateKeys%22%3B%0A%0Alet+keys+%3D+await+generateKeys%28%29%0A%0Aexport+let+exportedKeySetter+%3D+Promise.all%28%5B%0A++set%28%22exportedKeys%22%2C+keys%29%2C%0A++set%28%22publicKey%22%2C+keys.publicKey%29%0A%5D%29)
182. On [your publicKey](https://www.val.town/v/me/publicKey) click the lock icon🔒 to change the permissions to `Unlisted`.
193. [Fork this helper function](https://www.val.town/v/stevekrouse.turso/fork) replacing `stevekrouse` with your own username
204. [Try out some queries!](https://www.val.town/v/stevekrouse.tursoExamples/fork)
21
35## Architecture
36
37This @std.turso function is the client or SDK to @std.tursoAPI, which acts as a "proxy" to Turso. It handles authentication, creates databases, and forwards on your SQL queries. You can get lower latency (~200ms vs ~800ms), more storage, databases, CLI & API access by having your own Turso account.
38
39Migrated from folder: turso/turso
12
131. This val requires you to setup public key auth, which is really just three clicks here: https://blog.val.town/public-key-auth-val-town-users-can-be-your-users
142. [Optional] You can setup a helper function so you don't have to pass your keys every time:
15
16```js
18```
19
20Warning: Do **not** make your blob function public or unlisted. That would allow anyone to use it.
21
22## Usage
22
23```js
24function updateFeedback(ref) {
25 let feedback = [...document.getElementsByTagName('a')].find(e => e.innerText == 'Feedback')
26 feedback.setAttribute('href', "https://stevekrouse-docfeedbackform.web.val.run/?ref=" + ref)
30```
31
32Finally, you may be wondering why I queue up feedback in `@stevekrouse.docsFeedback`, a private JSON val, and then process it via [`@stevekrouse.formFeedbackAlert`](https://www.val.town/v/stevekrouse.formFeedbackAlert) instead of sending it along to Discord directly in this val. I [tried that originally](https://www.val.town/v/stevekrouse.docFeedbackForm?v=61) but it felt too slow to wait for the API call to Discord before returning the "Thanks for your feedback" message. This is where the `context.waitUntil` method (that Cloudflare workers and Vercel Edge Functions support) would really come in handy – those allow you to return a Response, and then continue to compute. Currently Val Town requires you to stop all compute with the returning of your Response, so the only way to compute afterwards is to queue it up for another val to take over, and that's what I'm doing here.
33
34
1## Get Weather
2
3Simple function to get weather data from the free [wttr.in](https://wttr.in/:help) service.
4
5```ts
1# Get the day of week name
2
3JavaScript's [`Date.prototype.getDay()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDay) returns a number that represents the day of the week, `0` for Sunday, `1` for Monday, etc. This function returns the name of the week, ie `"Sunday"`, `"Monday"`, etc.
4
5The function optionally inputs a `Date` object, but will default to the current time if none is provided.
6
7Migrated from folder: Archive/getDayName
7## Authentication
8
9This function requires two keys: one from Github to get your gists, and one from Val Town to make the vals in your account:
10
111. Github token: https://github.com/settings/tokens
14## Usage
15
16You can use this function by calling it and passing your keys like so:
17
18```
3This is an example of using the tiny [peko](https://peko.deno.dev/) example with Val Town - it's a small router that lets you build web apps using the standard [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) & [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) objects.
4
5Peko just provides routing - matching URLs with functions - and lets you create your own Response object.
6
7### Server examples
1# luxon
2
3[Luxon](https://moment.github.io/luxon/#/?id=luxon) is, like [date-fns](https://www.val.town/v/tmcw.datefnsExample), a good option for formatting, parsing, and manipulating dates. It's more of a direct successor to [moment](https://www.val.town/v/tmcw.momentExample) and has a similar method-chain-oriented API rather than function-call oriented API like date-fns.
4
5Migrated from folder: Modules/luxonExample
1# ramda
2
3[ramda](https://ramdajs.com/) is a module like [lodash](https://www.val.town/v/tmcw.lodashExample) or [underscore](https://www.val.town/v/tmcw.underscoreExample) but with a much heavier emphasis on functional programming. It lets you do the same kind of things but in a much 🌶️ spicier, 💪 more macho, 🤔 sometimes confusing style. I was really into this module in my late 20s.
4
5Migrated from folder: Modules/ramdaExample