Wednesday, October 24, 2012

List in groovy-wslite request

Groovy-wslite is currently recommended way for doing client calls to web services from groovy. It has very interesting format for describing requests, unfortunately it is not very well documented, and for me it was totally unclear how to send lists of objects to service. Fortunately, source code is available and is easy to dig if you have some time.
Basically, all you need to do is just send a bunch of regular objects, and they will be combined in list on the other end. There is example:

def response = client.send(SOAPAction:'https://server/services/service') {
  body {
    create() {
      dto {
        name('name123')
        id('123456')
        child {
              name('child1')
              birthday('2011-01-01')
            }
        child {
              name('child2')
              birthday('2012-01-01')
            }
      }
    }
  }
}


2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi Dmitrijs, can you give us an example of how serious in wslite (The following code, node.js) need to create a record in a airtable base (airtable.com), and fail in the attempt.

    wslite works perfect with wsdl, but with these API (air table) have not succeeded.

    regards
    Draco


    CODE NODE.JS
    var Airtable = require('airtable');
    var base = new Airtable({ apiKey: 'YOUR_API_KEY' }).base('appscSNuNfESXiAq9');

    base('ouiTKNde').create({
    "date": "2016-02-01",
    "ts": "2016-02-01T04:30:00.000Z",
    "Or": "ST",
    "DT": "61",
    "De": "OU",
    "xml": "yes"
    }, function(err, record) {
    if (err) { console.log(err); return; }
    console.log(record);
    });


    the same example in CURL
    $ curl -v -XPOST https://api.airtable.com/v0/appscSNuNfESXiAq9/resource
    -H "Authorization: Bearer YOUR_API_KEY"
    -H "Content-type: application/json"
    -d '{
    "fields": {
    "date": "2016-02-01",
    "ts": "2016-02-01T04:30:00.000Z",
    "Ori": "ST",
    "DT": "61",
    "De": "OU",
    "xml": "yes"
    }
    }'

    ReplyDelete