We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1069bd9 commit 7299b3fCopy full SHA for 7299b3f
pages/api/posts.ts
@@ -0,0 +1,25 @@
1
+import { NextApiRequest, NextApiResponse } from 'next'
2
+
3
+module.exports = async (req: NextApiRequest, res: NextApiResponse) => {
4
+ if (req.method === 'GET') {
5
+ const posts = [
6
+ {
7
+ id: 1,
8
+ title: 'React',
9
+ body: 'React is the JavaScript library for building UIs.',
10
+ date: '2020-01-01',
11
+ },
12
13
+ id: 2,
14
+ title: 'Next.js',
15
+ body: 'Next.js is the framework for React developers.',
16
+ date: '2020-02-01',
17
18
+ ]
19
20
+ res.status(200).json({ posts })
21
+ res.end()
22
+ } else {
23
+ res.end(`Invalid method ${req.method}. Only GET is allowed.`)
24
+ }
25
+}
0 commit comments