i399exback/express-examples/express2.js

23 lines
540 B
JavaScript
Raw Permalink Normal View History

2017-04-04 15:57:10 +03:00
'use strict';
const express = require('express');
const app = express();
2017-04-08 09:17:59 +03:00
app.use(express.static('./'));
2017-04-04 15:57:10 +03:00
app.get('/api/contacts', getContacts);
app.get('/api/contacts/:id', getContact);
app.listen(3000);
function getContacts(request, response) {
response.set('Content-Type', 'application/json');
response.end(JSON.stringify([{ id: 1 }, { id: 2 }]));
}
function getContact(request, response) {
var id = request.params.id;
response.set('Content-Type', 'application/json');
response.end(JSON.stringify({ id: id }));
}