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

Pre-request and post-request for api collections #557

Open
WrathOP opened this issue Feb 3, 2025 · 1 comment
Open

Pre-request and post-request for api collections #557

WrathOP opened this issue Feb 3, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@WrathOP
Copy link
Contributor

WrathOP commented Feb 3, 2025

Add Pre/Post Request Scripts to APIDash

Why We Need This

I've been using APIDash for my API testing, and it's great! However, I often find myself manually adding auth tokens or transforming data for each request. This gets tedious, especially when working with authenticated APIs or when I need to chain multiple requests together.

What I'm Looking For

I'd love to see something similar to Postman's pre-request and test scripts in APIDash. The idea is to have a simple code editor where we can write JavaScript that runs before and after our requests. This would help with:

  • Adding auth tokens automatically (no more copy-pasting!)
  • Setting up environment variables through code
  • Transforming request/response data on the fly
  • Chaining API calls (like when you need to get a token first)
  • Basic testing and validation

Example Use Cases

  1. Auth Token Management

    // Pre-request: Add token to headers
    request.headers['Authorization'] = `Bearer ${env.get('AUTH_TOKEN')}`;
  2. Dynamic Variables

    // Set an env variable based on response
    env.set('USER_ID', response.body.id);
  3. Request Chaining

    // Get fresh token if expired
    if (response.status === 401) {
      // Refresh token logic here
      env.set('AUTH_TOKEN', newToken);
    }

Why This Would Be Awesome

  • Saves time on repetitive tasks
  • Makes working with auth much easier
  • Helps automate testing flows
  • Great for complex API workflows

I personally use these features a lot in Postman, and having them in APIDash would make it even better for my daily API development work. Would love to help test this if it gets implemented!

Technical Notes

  • Need a way to access/modify environment variables
  • Should be able to modify request/response data
  • Basic console for debugging would be helpful
@WrathOP WrathOP added the enhancement New feature or request label Feb 3, 2025
@ashitaprasad
Copy link
Member

Definitely a useful feature which was added to the roadmap - "Save items in Response headers/body in an Environment variable to be used by other requests. Something like a post-processing script."

Will also resolve #465

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants