Skip to content

Instantly share code, notes, and snippets.

@rzvdaniel
Created July 6, 2019 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rzvdaniel/db18be347423075f39b121a287c8f67b to your computer and use it in GitHub Desktop.
Save rzvdaniel/db18be347423075f39b121a287c8f67b to your computer and use it in GitHub Desktop.
[Medium] Moleculer Routing - RESTful Aliases
// 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