i399exexpress/examples/express3.js
2017-05-09 15:42:06 +03:00

22 lines
498 B
JavaScript

'use strict';
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.get('/api/tasks', getTasks);
app.post('/api/tasks', saveTask);
app.listen(3000, () => console.log('Server is running...'));
function getTasks(request, response) {
response.json([{ id: 1 }, { id: 2 }]);
}
function saveTask(request, response) {
console.log(request.body); // request should have correct content-type
response.end();
}