-
-
Save rkstedman/1a66fb733cd9c48fb43b to your computer and use it in GitHub Desktop.
[restify] set a base url for all routes
This file contains 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
# Usage example: server.get url('read','animals','list'), (req, res, next) -> | |
# Helper function to set base url and human readable names for all routes | |
exports.url = (method, resource, type, opts) -> | |
if type is 'list' | |
name = "#{method}_#{resource}_list_url" | |
path = "/v1#{opts?.rootPath || ''}/#{resource}" | |
else | |
singular = resource.slice(0,-1) | |
name = "#{method}_#{singular}_url" | |
path = "/v1#{opts?.rootPath || ''}/#{resource}/:#{singular}" | |
return {name,path} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment