Advertisement
DariuszKralewski

Untitled

Apr 4th, 2020
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. const express = require('express');
  2. const router = express.Router();
  3. // route z listą wszystkich produktów
  4. router.get('/', (req, res, next) => {
  5. res.status(200).json({
  6. wiadomosc: 'Lista wszystkich produktów'
  7. });
  8. });
  9. //route dodający nowy produkt
  10. router.post('/', (req, res, next) => {
  11. res.status(200).json({
  12. wiadomosc: 'Dodano nowy produkt'
  13. });
  14. });
  15. //route pokazujący szczegóły produktu o podanym id
  16. router.get('/:productId', (req, res, next) => {
  17. const id = req.params.productId; // wyciągnąłem id z parametru
  18. res.status(200).json({
  19. wiadomosc: 'Szczegóły produktu o nr ' + id
  20. });
  21. });
  22. router.patch('/:productId', (req, res, next) => {
  23. const id = req.params.productId; // wyciągnąłem id z parametru
  24. res.status(200).json({
  25. wiadomosc: 'Zmieniono dane produktu nr ' + id
  26. });
  27. });
  28. router.delete('/:productId', (req, res, next) => {
  29. const id = req.params.productId; // wyciągnąłem id z parametru
  30. res.status(200).json({
  31. wiadomosc: 'Usunięto produkt o nr ' + id
  32. });
  33. });
  34.  
  35. module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement