front/stubs/api/books/index.js

37 lines
643 B
JavaScript
Raw Normal View History

2024-09-28 12:51:59 +03:00
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'
})
})