5

Are there plans for enabling PAW to generate code from the JSON response? Or exponse a javascript API to do that? I would like to generate obj-c or swift classes based on the response.

Victor Bogdan
  • 2,022
  • 24
  • 33
  • Great idea! Hope I gave you some pointers to make what you need. If we get the chance, we will try to hack something to generate code from responses... definitively keep us updated on what you do with it – Micha Mazaheri Jun 24 '15 at 22:59

1 Answers1

0

It's true that no code generator does that, but the JavaScript API exists, you can see here the Overview of what's possible and here's the full API Reference. Here's also a quick tutorial on how to make a code generator in Paw.

Here's a snippet on how to get JSON from the latest HTTP response of a given request:

var MyCodeGenerator = function() {
    this.generate = function(context) {
        var responseBody = context.getCurrentRequest().getLastExchange().responseBody;
        var responseObject = JSON.parse(responseBody); // JSON object
        return JSON.stringify(responseObject); // just an example
    };
}

MyCodeGenerator.identifier = "com.mycompany.MyCodeGenerator";

MyCodeGenerator.title = "My Code Generator";
Micha Mazaheri
  • 3,481
  • 1
  • 21
  • 26