backend init
This commit is contained in:
6
stubs/api/books/book-list.json
Normal file
6
stubs/api/books/book-list.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"content": {
|
||||
|
||||
},
|
||||
"totalElement": 0
|
||||
}
|
||||
5
stubs/api/books/book.json
Normal file
5
stubs/api/books/book.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"id": "1",
|
||||
"name": "Book name",
|
||||
"description": "Interesting book description"
|
||||
}
|
||||
36
stubs/api/books/index.js
Normal file
36
stubs/api/books/index.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const booksRouter = require('express').Router();
|
||||
|
||||
module.exports = booksRouter;
|
||||
|
||||
const books = []
|
||||
|
||||
booksRouter.get('/list', (req, res) => {
|
||||
res.send(require('./book-list.json'))
|
||||
})
|
||||
|
||||
booksRouter.post('/', (req, res) => {
|
||||
// body() can be used because of dev server
|
||||
console.log(req.body)
|
||||
books.push({
|
||||
name: req.body.name,
|
||||
})
|
||||
|
||||
res.send({
|
||||
status: 200
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
booksRouter.get('/:id', (req, res) => {
|
||||
console.log(req.params);
|
||||
|
||||
res.send(require('./book.json'));
|
||||
|
||||
// res.status(404).send()
|
||||
})
|
||||
|
||||
booksRouter.delete('/:id', (req, res) => {
|
||||
res.status(201).send({
|
||||
status: 'ok'
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user