Last active
July 6, 2019 17:37
-
-
Save rzvdaniel/d2c5b1c2f420f1005b64267991f7db1b to your computer and use it in GitHub Desktop.
[Medium] Moleculer Routing - Auto 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
// users.service.js | |
module.exports = { | |
name: "users", | |
actions: { | |
list: { | |
// Expose as "/users/" | |
rest: "GET /", | |
handler(ctx) { | |
return "GET Users list"; | |
} | |
}, | |
get: { | |
// Expose as "/users/:id" | |
rest: "GET /:id", | |
handler(ctx) { | |
return `GET user with Id = ${ctx.params.id}`; | |
} | |
}, | |
create: { | |
// Expose as "/users/" | |
rest: "POST /", | |
params: { | |
name: { type: "string" } | |
}, | |
handler(ctx) { | |
return `CREATE user with name = ${ctx.params.name}`; | |
} | |
}, | |
update: { | |
// Expose as "/users/:id" | |
rest: "PUT /:id", | |
params: { | |
name: { type: "string" } | |
}, | |
handler(ctx) { | |
return `UPDATE name of user with id = ${ctx.params.id}. New name: ${ | |
ctx.params.name | |
}`; | |
} | |
}, | |
remove: { | |
// Expose as "/users/:id" | |
rest: "DELETE /:id", | |
handler(ctx) { | |
return `DELETE user with id = ${ctx.params.id}`; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment