Paw REST Client - generate objects from JSON response

474 Views Asked by At

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.

1

There are 1 best solutions below

0
Micha Mazaheri On

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";