Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

EWD 3 Training Course Part 9: Complex QEWD Messages and Responses

540 views

Published on

This presentation is Part 9 of the EWD 3 Training Course. It explains how you can construct and send complex messages from the browser to the QEWD back-end, and how to construct and return complex messages back to the browser.

Published in: Software
  • Be the first to comment

  • Be the first to like this

EWD 3 Training Course Part 9: Complex QEWD Messages and Responses

  1. 1. Copyright © 2016 M/Gateway Developments Ltd EWD 3 Training Course Part 9 Complex QEWD messages and responses Rob Tweed Director, M/Gateway Developments Ltd Twitter: @rtweed
  2. 2. Copyright © 2016 M/Gateway Developments Ltd Sending complex messages • So far we've just sent the simplest message possible: – Only has a type property, and no additional content or payload • Messages can be as big and as complex as you like – Just JavaScript objects
  3. 3. Copyright © 2016 M/Gateway Developments Ltd Sending complex messages • Define the content or payload in the message object's params property var messageObj = { type: 'login', params: { username: $('#username').val(), password: $('#password').val() } }; EWD.send(messageObj, callbackFn);
  4. 4. Copyright © 2016 M/Gateway Developments Ltd Handling Complex Messages • In back-end handler, params available via messageObj.params: login: function(messageObj, session, send, finished) { var username = messageObj.params.username; if (username === '') { finished({error: 'You must enter a username'); return; } var password = messageObj.params.password; if (password === '') { finished({error: 'You must enter a password'); return; } // …etc }
  5. 5. Copyright © 2016 M/Gateway Developments Ltd Sending complex messages • Params can be as complex an object as you wish var messageObj = { type: 'complex', params: { foo: 'bar', subObj: { hello: 'world', name: 'rob' }, arr: ['a', 'b', 'c'] } }; EWD.send(messageObj, callbackFn);
  6. 6. Copyright © 2016 M/Gateway Developments Ltd Sending complex messages • Params can be as complex an object as you wish var messageObj = { type: 'complex', params: { foo: 'bar', subObj: { hello: 'world', name: 'rob' }, arr: ['a', 'b', 'c'] } }; EWD.send(messageObj, callbackFn); At back-end: var name = messageObj.params.subObj.name;
  7. 7. Copyright © 2016 M/Gateway Developments Ltd Sending complex messages • Params can be as complex an object as you wish var messageObj = { type: 'complex', params: { foo: 'bar', subObj: { hello: 'world', name: 'rob' }, arr: ['a', 'b', 'c'] } }; EWD.send(messageObj, callbackFn); At back-end: var b = messageObj.params.arr[1];
  8. 8. Copyright © 2016 M/Gateway Developments Ltd Returning Complex Responses • The response object returned by the back- end handler's send() or finished() functions can be as complex as you want • Be careful with the response size: – Can significantly slow down ewd-qoper8 – The larger the response, the longer it takes for Express to return it to the browser or client
  9. 9. Copyright © 2016 M/Gateway Developments Ltd Returning Complex Responses finished({ foo: 'bar', myObj: { hello: 'world', name: 'Rob' } myArr: ['a','b','c'] });
  10. 10. Copyright © 2016 M/Gateway Developments Ltd Returning Complex Responses finished({ foo: 'bar', myObj: { hello: 'world', name: 'Rob' } myArr: ['a','b','c'] }); Accessed in browser-side response handler as: responseObj.message.myObj.name In both EWD.send()'s callback and Pub/Sub handler

×