Coder Social home page Coder Social logo

happymedium / responsetofile-postman Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sivcan/responsetofile-postman

0.0 0.0 0.0 38 KB

This project helps in writing responses (or any data) from postman to a file locally.

JavaScript 100.00%

responsetofile-postman's Introduction

ResponseToFile-Postman

This project will help in writing the responses of a request from Postman.

This project is to be used with template from Postman.

Steps to install the template

  1. Launch Postman Native App Download Postman
  2. Visit the following URL: https://documenter.getpostman.com/view/3407886/RWgp1fB5
  3. Click โ–บ Run In Postman and open with the native app

The collection that was imported makes it easy for users who want to write the response of each request to a file. This can be extended to write anything for eg. meta information or value of variables being used.

PRs are welcome.


Collection Docs: This collection makes it easy for users who want to write the response of each request to a file. This can be extended to write anything for eg. meta information or value of variables being used.

This project is using a powerful feature built in postman called as pm.sendRequest, the docs for which can be found here: https://learning.postman.com/docs/postman/scripts/postman-sandbox-api-reference/#pmsendrequest

Requirements

To work with this script, a local server is required. You can choose to write your own local server or edit the one provided below as per your needs.

Steps To Use

  1. Put all the requests you want to write the responses for, under this collection.

  2. Clone the following repository to your machine - https://github.com/sivcan/ResponseToFile-Postman or use the following command - git clone https://github.com/sivcan/ResponseToFile-Postman

  3. Navigate into the directory and install the dependencies. Use the following command: npm i

  4. Run the local server. Use the following command: node script.js

  5. Now, the responses for every request which is a part of this collection will be written to the Responses folder inside the project repo. You can modify the local server's code to change the file location.

  6. Run your requests through builder / run through collection runner and store your data locally.

You can modify the script and the local server to support more data formats / data that you want to write to the file.

Additionally

Instead of moving each request under this collection, you can copy the script from the Tests tab of this collection to the Tests tab of any request or even a specific folder.

Note: To access the Tests script of this collection:

  1. You need to Right Click the Write Responses To File collection in the sidebar.
  2. Click on Edit
  3. Go to Tests tab.

Then you can send that particular request / requests under a folder for which the data needs to be written.

File Extensions

You can also modify the extension of the file.

Example: In case you want to write CSV data to a file, all you need to do is change the fileExtension property in the Tests script to csv.

File Support

You can modify the opts variable as per your need under the Tests tab of the collection, the following features are supported:

  1. If you want all the data to be written to a single file then you can modify the value of mode to appendFile instead of writeFile (More functions here: Node FS)

  2. If you want each response to be stored in a different file, then you can provide a uniqueIdentifier such as Date.now() or some environment variable as a counter, and it'll be used generate unique file names. You can also make the value of uniqueIdentifier as true and the server will internally append a unique number to every file name.

  3. You can provide options to the FS lib, e.g. options: { encoding: 'base64' }.

responsetofile-postman's People

Contributors

sivcan avatar danielwinklermedel avatar gabrielsroka avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.