Skip to content

Instantly share code, notes, and snippets.

@joadr
Last active November 19, 2020 02:42
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 joadr/f79a4f42a43fc1ff760ca77d66e3935e to your computer and use it in GitHub Desktop.
Save joadr/f79a4f42a43fc1ff760ca77d66e3935e to your computer and use it in GitHub Desktop.
insomnia-plugin-pathname
/**
* 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