From 9399f7fe68cf56497005fbf7577cda2a458514c9 Mon Sep 17 00:00:00 2001 From: Jashn Date: Thu, 1 Oct 2020 09:49:34 +0530 Subject: [PATCH 1/2] change anonymous functions to named in docs examples --- docs/advanced-features/preview-mode.md | 6 +++--- docs/api-routes/dynamic-api-routes.md | 4 ++-- docs/api-routes/introduction.md | 4 ++-- docs/api-routes/response-helpers.md | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/advanced-features/preview-mode.md b/docs/advanced-features/preview-mode.md index a1b05fb09c651..3d51fa6117654 100644 --- a/docs/advanced-features/preview-mode.md +++ b/docs/advanced-features/preview-mode.md @@ -39,7 +39,7 @@ First, create a **preview API route**. It can have any name - e.g. `pages/api/pr In this API route, you need to call `setPreviewData` on the response object. The argument for `setPreviewData` should be an object, and this can be used by `getStaticProps` (more on this later). For now, we’ll use `{}`. ```js -export default (req, res) => { +export default function myPreviewRoute(req, res) { // ... res.setPreviewData({}) // ... @@ -54,7 +54,7 @@ You can test this manually by creating an API route like below and accessing it // A simple example for testing it manually from your browser. // If this is located at pages/api/preview.js, then // open /api/preview from your browser. -export default (req, res) => { +export default function myPreviewRoute(req, res) { res.setPreviewData({}) res.end('Preview mode enabled') } @@ -175,7 +175,7 @@ By default, no expiration date is set for the preview mode cookies, so the previ To clear the preview cookies manually, you can create an API route which calls `clearPreviewData` and then access this API route. ```js -export default (req, res) => { +export default function clearMyPreview(req, res) { // Clears the preview mode cookies. // This function accepts no arguments. res.clearPreviewData() diff --git a/docs/api-routes/dynamic-api-routes.md b/docs/api-routes/dynamic-api-routes.md index 272f68025f7e2..f7587a9df5e0a 100644 --- a/docs/api-routes/dynamic-api-routes.md +++ b/docs/api-routes/dynamic-api-routes.md @@ -16,7 +16,7 @@ API routes support [dynamic routes](/docs/routing/dynamic-routes.md), and follow For example, the API route `pages/api/post/[pid].js` has the following code: ```js -export default (req, res) => { +export default function dynamicRoute(req, res) { const { query: { pid }, } = req @@ -68,7 +68,7 @@ And in the case of `/api/post/a/b`, and any other matching path, new parameters An API route for `pages/api/post/[...slug].js` could look like this: ```js -export default (req, res) => { +export default function allDynamicRoutes(req, res) { const { query: { slug }, } = req diff --git a/docs/api-routes/introduction.md b/docs/api-routes/introduction.md index 9d71dc4aca031..a9574dbe588a6 100644 --- a/docs/api-routes/introduction.md +++ b/docs/api-routes/introduction.md @@ -22,7 +22,7 @@ Any file inside the folder `pages/api` is mapped to `/api/*` and will be treated For example, the following API route `pages/api/user.js` handles a `json` response: ```js -export default (req, res) => { +export default function myApiRoute(req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'application/json') res.end(JSON.stringify({ name: 'John Doe' })) @@ -37,7 +37,7 @@ For an API route to work, you need to export as default a function (a.k.a **requ To handle different HTTP methods in an API route, you can use `req.method` in your request handler, like so: ```js -export default (req, res) => { +export default function httpMethods(req, res) { if (req.method === 'POST') { // Process a POST request } else { diff --git a/docs/api-routes/response-helpers.md b/docs/api-routes/response-helpers.md index fa4f6f2699cac..334ad81525ae2 100644 --- a/docs/api-routes/response-helpers.md +++ b/docs/api-routes/response-helpers.md @@ -15,7 +15,7 @@ description: API Routes include a set of Express.js-like methods for the respons The response (`res`) includes a set of Express.js-like methods to improve the developer experience and increase the speed of creating new API endpoints, take a look at the following example: ```js -export default (req, res) => { +export default function resHelper(req, res) { res.status(200).json({ name: 'Next.js' }) } ``` From 4d82ef9e5fc54fa3db3fbf6007cbb7b513ba4636 Mon Sep 17 00:00:00 2001 From: Jashn Date: Mon, 5 Oct 2020 14:11:23 +0530 Subject: [PATCH 2/2] change anonymous functions to named in docs example --- docs/advanced-features/preview-mode.md | 6 +++--- docs/api-routes/dynamic-api-routes.md | 4 ++-- docs/api-routes/introduction.md | 4 ++-- docs/api-routes/response-helpers.md | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/advanced-features/preview-mode.md b/docs/advanced-features/preview-mode.md index 3d51fa6117654..79ac857448dc0 100644 --- a/docs/advanced-features/preview-mode.md +++ b/docs/advanced-features/preview-mode.md @@ -39,7 +39,7 @@ First, create a **preview API route**. It can have any name - e.g. `pages/api/pr In this API route, you need to call `setPreviewData` on the response object. The argument for `setPreviewData` should be an object, and this can be used by `getStaticProps` (more on this later). For now, we’ll use `{}`. ```js -export default function myPreviewRoute(req, res) { +export default function handler(req, res) { // ... res.setPreviewData({}) // ... @@ -54,7 +54,7 @@ You can test this manually by creating an API route like below and accessing it // A simple example for testing it manually from your browser. // If this is located at pages/api/preview.js, then // open /api/preview from your browser. -export default function myPreviewRoute(req, res) { +export default function handler(req, res) { res.setPreviewData({}) res.end('Preview mode enabled') } @@ -175,7 +175,7 @@ By default, no expiration date is set for the preview mode cookies, so the previ To clear the preview cookies manually, you can create an API route which calls `clearPreviewData` and then access this API route. ```js -export default function clearMyPreview(req, res) { +export default function handler(req, res) { // Clears the preview mode cookies. // This function accepts no arguments. res.clearPreviewData() diff --git a/docs/api-routes/dynamic-api-routes.md b/docs/api-routes/dynamic-api-routes.md index f7587a9df5e0a..702c822b101af 100644 --- a/docs/api-routes/dynamic-api-routes.md +++ b/docs/api-routes/dynamic-api-routes.md @@ -16,7 +16,7 @@ API routes support [dynamic routes](/docs/routing/dynamic-routes.md), and follow For example, the API route `pages/api/post/[pid].js` has the following code: ```js -export default function dynamicRoute(req, res) { +export default function handler(req, res) { const { query: { pid }, } = req @@ -68,7 +68,7 @@ And in the case of `/api/post/a/b`, and any other matching path, new parameters An API route for `pages/api/post/[...slug].js` could look like this: ```js -export default function allDynamicRoutes(req, res) { +export default function handler(req, res) { const { query: { slug }, } = req diff --git a/docs/api-routes/introduction.md b/docs/api-routes/introduction.md index a9574dbe588a6..dd4ba2c4bbb76 100644 --- a/docs/api-routes/introduction.md +++ b/docs/api-routes/introduction.md @@ -22,7 +22,7 @@ Any file inside the folder `pages/api` is mapped to `/api/*` and will be treated For example, the following API route `pages/api/user.js` handles a `json` response: ```js -export default function myApiRoute(req, res) { +export default function handler(req, res) { res.statusCode = 200 res.setHeader('Content-Type', 'application/json') res.end(JSON.stringify({ name: 'John Doe' })) @@ -37,7 +37,7 @@ For an API route to work, you need to export as default a function (a.k.a **requ To handle different HTTP methods in an API route, you can use `req.method` in your request handler, like so: ```js -export default function httpMethods(req, res) { +export default function handler(req, res) { if (req.method === 'POST') { // Process a POST request } else { diff --git a/docs/api-routes/response-helpers.md b/docs/api-routes/response-helpers.md index 334ad81525ae2..094101aa1319f 100644 --- a/docs/api-routes/response-helpers.md +++ b/docs/api-routes/response-helpers.md @@ -15,7 +15,7 @@ description: API Routes include a set of Express.js-like methods for the respons The response (`res`) includes a set of Express.js-like methods to improve the developer experience and increase the speed of creating new API endpoints, take a look at the following example: ```js -export default function resHelper(req, res) { +export default function handler(req, res) { res.status(200).json({ name: 'Next.js' }) } ```