Created
October 28, 2016 09:45
-
-
Save ztrehagem/10cdf453aacde39bc39e04ca9c308301 to your computer and use it in GitHub Desktop.
rest uri builder
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
function build(uri, params) { | |
console.log('@', uri, ' <- ', params); | |
var built = uri.replace(/\/:[^/]+/g, function(match) { | |
var key = match.substring(2); | |
return '/' + params[key]; | |
}); | |
console.log('built:', built); | |
} | |
build('/hoge/:fuga/:foobar', { | |
fuga: 123, | |
foobar: 'abc' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment