Skip to content

Instantly share code, notes, and snippets.

@rkstedman
Created April 24, 2015 03:34
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 rkstedman/1a66fb733cd9c48fb43b to your computer and use it in GitHub Desktop.
Save rkstedman/1a66fb733cd9c48fb43b to your computer and use it in GitHub Desktop.
[restify] set a base url for all routes
# 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