-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f8c21e
commit 68eb1be
Showing
15 changed files
with
55 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ This guide will walk you through the steps to get started with Nuxt API Party. | |
npx nuxi@latest module add api-party | ||
``` | ||
|
||
## Step 2: Use the `nuxt-api-party` module | ||
## Step 2: Use the `nuxt-api-party` Module | ||
|
||
Add `nuxt-api-party` to your Nuxt configuration: | ||
|
||
|
@@ -19,7 +19,7 @@ export default defineNuxtConfig({ | |
}) | ||
``` | ||
|
||
## Step 3: Set Up API Endpoints | ||
## Step 3: Set up API Endpoints | ||
|
||
Prepare your first API connection by setting an endpoint object. Each key represents an endpoint ID, which is used to generate the composables. The value is an object with the following properties: | ||
|
||
|
@@ -50,7 +50,7 @@ export default defineNuxtConfig({ | |
For the API endpoint `jsonPlaceholder` above, the following composables are generated: | ||
|
||
- `$jsonPlaceholder` – Returns the response data, similar to [`$fetch`](https://nuxt.com/docs/api/utils/dollarfetch#fetch) | ||
- `useJsonPlaceholderData` – Returns [multiple values](/api/use-my-api-data.html#return-values) similar to [`useFetch`](https://nuxt.com/docs/api/composables/use-fetch) | ||
- `useJsonPlaceholderData` – Returns [multiple values](/api/use-fetch-like.html#return-values) similar to [`useFetch`](https://nuxt.com/docs/api/composables/use-fetch) | ||
|
||
::: tip | ||
Connect to as many API endpoints as you like. Each endpoint will generate two composables. | ||
|
@@ -100,6 +100,6 @@ const { data, pending, refresh, error } = await useJsonPlaceholderData('posts/1' | |
</template> | ||
``` | ||
|
||
## Step. 5: Your Turn | ||
## Step 5: Your Turn | ||
|
||
Create something awesome! I'm eager to find out what you have built. [Drop me a line](mailto:[email protected]), if you want. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
# How It Works | ||
|
||
## tl;dr | ||
|
||
The internal `/api/__api_party` server route will proxy your API request. | ||
**tl;dr:** The internal `/api/__api_party` server route will proxy your API request. | ||
|
||
::: tip | ||
The proxy layer will not only pass through your API's response body to the response on the client, but also HTTP status code, HTTP status message and headers. This way, you can handle errors just like you would with a direct API call. | ||
::: | ||
|
||
## Detailed Answer | ||
|
||
The generated composables will initiate a POST request to the Nuxt server route `/api/__api_party`, which then initiates the actual request for a given route to your API and passes the response back to the client. This proxy behavior has the benefit of keeping your API credentials safe from the client and omitting CORS issues, since data is sent from server to server. | ||
|
||
During server-side rendering, calls to the Nuxt server route will directly call the relevant function (emulating the request), saving an additional API call. | ||
|
||
::: tip | ||
Responses are cached and hydrated to the client. Subsequent calls will return cached responses, saving duplicated requests. | ||
::: | ||
## Hydration | ||
|
||
API calls executed on the server (SSR) are hydrated on the client to avoid unnecessary API calls. Thus, a request initiated on the server will not be executed again on the client. | ||
|
||
## Nuxt Static Generation | ||
|
||
When using `nuxi generate` to pre-render your application, the result of each API call is stored in the [Nuxt `payload`](https://nuxt.com/docs/api/composables/use-nuxt-app#payload). |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.