From 14307d13276b0be37ee42fa833a396055ef90bc4 Mon Sep 17 00:00:00 2001 From: Krutie Patel Date: Wed, 9 Nov 2022 19:09:48 +1000 Subject: [PATCH] docs(api): add `useRequestHeaders` composable example (#8833) Co-authored-by: Daniel Roe --- .../1.composables/use-request-headers.md | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/content/3.api/1.composables/use-request-headers.md b/docs/content/3.api/1.composables/use-request-headers.md index 90115ece837..4b928a8fa21 100644 --- a/docs/content/3.api/1.composables/use-request-headers.md +++ b/docs/content/3.api/1.composables/use-request-headers.md @@ -5,7 +5,7 @@ description: "Use useRequestHeaders to access the incoming request headers." # `useRequestHeaders` -Within your pages, components, and plugins you can use `useRequestHeaders` to access the incoming request headers. +You can use built-in `useRequestHeaders` composable to access the incoming request headers within your pages, components, and plugins. ```js // Get all request headers @@ -18,3 +18,21 @@ const headers = useRequestHeaders(['cookie']) ::alert{icon=👉} In the browser, `useRequestHeaders` will return an empty object. :: + +## Example + +We can use `useRequestHeaders` to access and proxy the initial request's `authorization` header to any future internal requests during SSR. + +The example below adds the `authorization` request header to an isomorphic `$fetch` call. + +```vue [pages/some-page.vue] + +``` + +::alert{icon=👉} +[Another example](/getting-started/data-fetching#example-pass-client-headers-to-the-api) shows how we can pass cookies from the initial request to another API route. +::