Last active
November 19, 2020 02:42
-
-
Save joadr/f79a4f42a43fc1ff760ca77d66e3935e to your computer and use it in GitHub Desktop.
insomnia-plugin-pathname
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
/** | |
* For an url like this: https://api.somewebsite.com/v1/some_path | |
* this will return /v1/some_path | |
*/ | |
module.exports.templateTags = [{ | |
name: 'pathname', | |
displayName: 'pathname', | |
description: 'pathname', | |
async run (context) { | |
let {url: contextUrl} = await context.util.models.request.getById(context.meta.requestId) | |
const compiled = _.template(contextUrl, {interpolate: /{{([\s\S]+?)}}/g}) | |
const url = new URL(compiled(context.context)) | |
return url.pathname | |
} | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment