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
Copy file name to clipboardExpand all lines: packages/docs/src/pages/qwikcity/endpoint/data.mdx
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,9 @@ The first step is to layout out the files so that we can accept `https://example
20
20
21
21
## Implement Endpoint
22
22
23
-
An endpoint is a `doGet` function that retrieves data (typically from a database, or other stores.) The retrieved data can be returned directly as JSON or used as an input to the component to render HTML. The `doGet` function receives the `params` to extract the parameters used to do data lookup.
23
+
An endpoint is a `onGet` function that retrieves data (typically from a database, or other stores.) The retrieved data can be returned directly as JSON or used as an input to the component to render HTML. The `onGet` function receives the `params` to extract the parameters used to do data lookup.
24
24
25
-
The `doGet` function returns an object that contains:
25
+
The `onGet` function returns an object that contains:
26
26
-`status`: HTTP status code
27
27
-`headers`: HTTP headers to control caches etc...
28
28
-`body`: The body of the response to be returned as JSON or to be used as input to the HTML.
An endpoint `doGet` function retrieves data and makes it available as JSON. The next step is to convert the JSON to HTML. This is done with a standard component as described [Components](/qwikcity/content/component). What is new is `useEndpoint()` to retrieve the data from the `doGet` function.
59
+
An endpoint `onGet` function retrieves data and makes it available as JSON. The next step is to convert the JSON to HTML. This is done with a standard component as described [Components](/qwikcity/content/component). What is new is `useEndpoint()` to retrieve the data from the `onGet` function.
1. Notice that the data endpoint and the component are defined in the same file. The data endpoint is serviced by the `doGet` function and the component is by the modules default export.
89
-
2. The component uses `useEndpoint()` function to retrieve the data. The `useEndpoint()` function invokes `doGet` function directly on the server but using `fetch()` on the client. Your component does not need to think about server/client differences when using data. The `useEndpoint()` function returns an object of type `Resource`. `Resource`s are promise-like objects that can be serialized by Qwik.
90
-
3. The `doGet` function is invoked before the component. This allows the `doGet` to return 404 or redirect in case the data is not available.
88
+
1. Notice that the data endpoint and the component are defined in the same file. The data endpoint is serviced by the `onGet` function and the component is by the modules default export.
89
+
2. The component uses `useEndpoint()` function to retrieve the data. The `useEndpoint()` function invokes `onGet` function directly on the server but using `fetch()` on the client. Your component does not need to think about server/client differences when using data. The `useEndpoint()` function returns an object of type `Resource`. `Resource`s are promise-like objects that can be serialized by Qwik.
90
+
3. The `onGet` function is invoked before the component. This allows the `onGet` to return 404 or redirect in case the data is not available.
91
91
4. Notice the use of `<Resource>` JSX element. The purpose of `Resource` is to allow the client to render different states of the `useEndpoint()` resource.
92
92
5. On the server the `<Resource>` element will pause rendering until the `Resource` is resolved or rejected. This is because we don't want the server to render `loading...`. (The server needs to know when the component is ready for serialization into HTML.)
The second case is a bit more complicated but it showcases how we can set the title of the page with the value that is retrieved from the `doGet` endpoint. (See [endpoint documentation](/qwikcity/endpoint/data) for retrieving data.) The Qwik City invokes `doGet` to retrieve the data for the route and then passes the data to the `head` function allowing it to create a custom title.
60
+
The second case is a bit more complicated but it showcases how we can set the title of the page with the value that is retrieved from the `onGet` endpoint. (See [endpoint documentation](/qwikcity/endpoint/data) for retrieving data.) The Qwik City invokes `onGet` to retrieve the data for the route and then passes the data to the `head` function allowing it to create a custom title.
0 commit comments