Created
July 6, 2019 17:50
-
-
Save rzvdaniel/db18be347423075f39b121a287c8f67b to your computer and use it in GitHub Desktop.
[Medium] Moleculer Routing - RESTful Aliases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// articles.service.js | |
module.exports = { | |
name: "articles", | |
actions: { | |
list: { | |
handler(ctx) { | |
return "GET articles list"; | |
} | |
}, | |
get: { | |
handler(ctx) { | |
return `GET the Article with Id = ${ctx.params.id}`; | |
} | |
}, | |
create: { | |
params: { | |
title: { type: "string" } | |
}, | |
handler(ctx) { | |
return `CREATE Article with title = ${ctx.params.title}`; | |
} | |
}, | |
update: { | |
params: { | |
title: { type: "string" } | |
}, | |
handler(ctx) { | |
return `UPDATE title of Article with Id = ${ | |
ctx.params.id | |
}. New title: ${ctx.params.title}`; | |
} | |
}, | |
remove: { | |
handler(ctx) { | |
return `DELETE Article with Id = ${ctx.params.id}`; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment