From a25a24ab2a92b5c07fa498cc98bb4b2145a2d4b8 Mon Sep 17 00:00:00 2001 From: catcarbonell Date: Thu, 1 Oct 2020 21:11:29 -0700 Subject: [PATCH] Gave names to anonymous functions. Tried to be as semantic as possible. --- docs/api-routes/dynamic-api-routes.md | 4 ++-- docs/api-routes/introduction.md | 4 ++-- docs/api-routes/response-helpers.md | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/api-routes/dynamic-api-routes.md b/docs/api-routes/dynamic-api-routes.md index 272f68025f7e..77e299c4ae0b 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 PostId(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 CatchSlug(req, res){ const { query: { slug }, } = req diff --git a/docs/api-routes/introduction.md b/docs/api-routes/introduction.md index 9d71dc4aca03..2d416eb51cf6 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 UserName(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 PostReq(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 fa4f6f2699ca..634f8f2f4650 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' }) } ```