Skip to content

Commit

Permalink
refine content and fix typo for API routes docs content (#1037)
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Apr 9, 2023
1 parent fa4e051 commit 3790710
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions www/pages/docs/api-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ linkheadings: 3

## API Routes

Greenwood has support for API routes, which are just functions that run on the server, and take in a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request), and return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).
Greenwood has support for API routes, which are just functions that run on the server, and take in a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request), and return a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response). Each API route must export an `async` function called **handler**.

### Usage

Expand All @@ -21,7 +21,7 @@ src/

Will yield an endpoint available at `/api/greeting`.

Here is an example of that API, which ready a query parameter of `name` and returns a JSON response.
Here is an example of that API, which reads a query parameter of `name` and returns a JSON response.

```js
export async function handler(request) {
Expand All @@ -39,7 +39,7 @@ export async function handler(request) {

### WCC

As [WCC](https://github.com/ProjectEvergreen/wcc) already comes with Greenwood, it can be used to generate HTML on the fly for over the wire transmission to the browser. This is great for generating HTML "fragments" on the server side using Web Components, thus being able to leverage your components on the client _and_ the server! As the HTML is added the DOM, if the custom element definition has been loaded client side too, these components will hydrate automatically and become instantly interactive. (think of appending more items to a virtualized list). 🚀
As [**WCC**](https://github.com/ProjectEvergreen/wcc) already comes with Greenwood, this could be used with API routes to generate HTML "fragments" on the server side using your projects Web Components, thus being able to leverage your components on the client _and_ the server! As the HTML is added to the DOM, if the custom element definition has been loaded client side too, these components will hydrate automatically and become instantly interactive. (think of appending more items to a virtualized list). 🚀

An example of rendering a "card" component in an API route might look like look this.
```js
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function handler(request) {
const { html } = await renderFromHTML(`
<x-card name="${name}"></x-card>
`, [
new URL('../components/card.js', import.meta.url)
new URL('path/to/card.js', import.meta.url)
]);

headers.append('Content-Type', 'text/html');
Expand Down

0 comments on commit 3790710

Please sign in to comment.