Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const router = express.Router();
- // route z listą wszystkich produktów
- router.get('/', (req, res, next) => {
- res.status(200).json({
- wiadomosc: 'Lista wszystkich produktów'
- });
- });
- //route dodający nowy produkt
- router.post('/', (req, res, next) => {
- res.status(200).json({
- wiadomosc: 'Dodano nowy produkt'
- });
- });
- //route pokazujący szczegóły produktu o podanym id
- router.get('/:productId', (req, res, next) => {
- const id = req.params.productId; // wyciągnąłem id z parametru
- res.status(200).json({
- wiadomosc: 'Szczegóły produktu o nr ' + id
- });
- });
- router.patch('/:productId', (req, res, next) => {
- const id = req.params.productId; // wyciągnąłem id z parametru
- res.status(200).json({
- wiadomosc: 'Zmieniono dane produktu nr ' + id
- });
- });
- router.delete('/:productId', (req, res, next) => {
- const id = req.params.productId; // wyciągnąłem id z parametru
- res.status(200).json({
- wiadomosc: 'Usunięto produkt o nr ' + id
- });
- });
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement