Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Plugin API - Response Context should allow access to the Environment #853

Closed
andrew-waters opened this issue Apr 8, 2018 · 3 comments

Comments

@andrew-waters
Copy link
Contributor

  • Insomnia Version: 5.15.0
  • Operating System: OS X 10.13.4

Details

I'm trying to write a plugin which works in the response context and cannot access any environment values when handling the response. It would also be necessary to view the request ion the same context.

Context - I'm trying to write a plugin which validates a response body against a path in an API spec. I don't want to hardcode the spec file location on disk and make those assumptions. I want to be able to set up a different spec file by directing users to create a key called schema which will be a string with an absolute path that the response handlers can access.

Pseudo:

const fs = require('fs');

module.exports.responseHooks = [
    context => {
        let body = context.response.getBody();
        if (body !== null) {
            let schemaLocation = context.response.getEnvironmentVariable('schema');
            if (schemaLocation !== undefined && fs.exists(schemaLocation)) {
                // does validation work here
            }
            
        }
    }
];

What you'll also notice is that where the validation work needs to happen, I would need to know the request method and endpoint so that I can dynamically search the schema based on path / method so really, the context in a response needs to have the request context available as well (minus any methods that can no longer apply - setHeader and other set methods for example).

@welcome
Copy link

welcome bot commented Apr 8, 2018

👋 Thanks for opening your first issue! If you're reporting a 🐞 bug, please make sure
you include steps to reproduce it. If you're requesting a feature 🎁, please provide real
use cases that would benefit. 👪

To help make this a smooth process, please be sure you have first read the
contributing guidelines.

@gschier
Copy link
Contributor

gschier commented Apr 9, 2018

Accessing the request should be easy to add. Environment hopefully as well. I'll try and get these new APIs into the next release!

@gschier
Copy link
Contributor

gschier commented Apr 25, 2018

This will work in the next release! 😀

module.exports.responseHooks = [
  context => {
    console.log('ENV', context.request.getEnvironmentVariable('foo'));
  }
];

luizmariz pushed a commit to luizmariz/insomnia that referenced this issue Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants