make post and put work the same way

This commit is contained in:
Jakub Sokołowski 2018-11-15 15:31:22 +01:00
parent 1c36339db7
commit 2226dabf54
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
1 changed files with 5 additions and 2 deletions

View File

@ -23,10 +23,13 @@ const App = (counter) => {
ctx.body = await counter.metrics()
})
router.put('/clicks/:id', async ctx => {
const clickIncrement = async ctx => {
ctx.body = { [ctx.params.id]: await counter.incr(ctx.params.id) }
ctx.status = 201
})
}
router.put('/clicks/:id', clickIncrement)
router.post('/clicks/:id', clickIncrement)
router.get('/clicks', async ctx => {
ctx.body = await counter.list()