You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
💡 Learn more about [caching](https://docs.netlify.com/platform/caching/) in our docs.
180
171
181
172
</details>
182
173
183
174
<details><summary>Part 3: Going serverless with Functions</summary>
184
175
185
-
```typescript
186
-
exportconst config:Config= {
187
-
method: "GET",
188
-
path: "/api/books{/:id}?",
176
+
**🧑💻 Relevant demo and code:**
177
+
178
+
-[Proxy to APIs](https://netlify-core-workshop.netlify.app/primitives/functions/proxy) ([netlify/functions/dad-joke.ts](https://github.com/netlify/netlify-workshop/blob/main/netlify/functions/dad-joke.ts))
179
+
-[Combine and filter APIs](https://netlify-core-workshop.netlify.app/primitives/functions/combine-and-filter) ([netlify/functions/platform-specific.ts](https://github.com/netlify/netlify-workshop/blob/main/netlify/functions/platform-specific.ts))
Serverless functions open a world of possibilities for running on-demand, server-side code without having to run a dedicated server.
183
+
184
+
With Netlify Functions, your serverless functions are version-controlled, built, and deployed along with the rest of your Netlify site, and we will automatically handle service discovery through our built-in API gateway. This eliminates overhead and brings the power of Deploy Previews and rollbacks to your functions.
185
+
186
+
By default, any JavaScript/TypeScript file in a site's `netlify/functions` directory will become a Function available at the `/.netlify/functions/{filename}` route. A simple Hello World would look like this:
187
+
188
+
```ts
189
+
// netlify/functions/hello-world.js
190
+
exportdefaultasync () => {
191
+
returnnewResponse("Hello world!");
189
192
};
190
193
```
191
194
192
-
💡 The `path` parameter follows the [URL Pattern API](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) spec.
195
+
Once deployed, you can visit `/.netlify/functions/hello-world` to invoke your Function in production.
193
196
194
197
💡 Learn more about [Functions](https://docs.netlify.com/functions/overview/) in our docs.
195
198
196
199
</details>
197
200
198
201
<details><summary>Part 4: Run middleware and personalize with Edge Functions</summary>
199
202
200
-
We're going to make a swag section of the site that is personalized to the user based on their geolocation. Edge functions act as middleware for the CDN — they run in front of other routes!
203
+
**🧑💻 Relevant demo and code:**
201
204
202
-
i. Edge Functions are also great places to add A/B testing. You can add a cookie at the edge to segment user traffic into groups (also known as buckets) to run experimentation. Set a new cookie in `netlify/edge-functions/abtest.ts`:
Edge functions are like Functions, but they execute closer to where your users are. While you can reach them as you would an endpoint, they can also chain in front of any route on your site. Think of them like middleware for the CDN: they can add HTTP headers and transform responses, passing along the next request, before ultimately reaching your users.
210
209
211
-
return response;
212
-
```
210
+
All this dynamic processing happens in a secure runtime based on Deno directly from the worldwide network edge location closest to each user for fast response times. Plus, you have the option to cache edge function responses for even faster response times. Edge functions are version-controlled, built, and deployed along with the rest of your site. This eliminates overhead and brings the power of Deploy Previews and rollbacks to your edge functions.
213
211
214
212
💡 Learn more about [Edge Functions](https://docs.netlify.com/edge-functions/overview/) in our docs.
0 commit comments