12 new API endpoints
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
function countWords(str) {
|
||||
return String(str).trim().split(/\s+/).filter(w => w.length > 0).length;
|
||||
}
|
||||
|
||||
router.post('/', (req, res) => {
|
||||
const { input } = req.body;
|
||||
res.json({ ret: countWords(input) });
|
||||
});
|
||||
|
||||
router.get('/:string', (req, res) => {
|
||||
res.json({ ret: countWords(req.params.string) });
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user