xp-forge / aws

AWS Core for the XP Framework
0 stars 0 forks source link

Marshal and unmarshal payloads #3

Closed thekid closed 1 year ago

thekid commented 1 year ago

Marshalling request payloads

Before this pull request, the following would raise lang.IllegalArgumentException (Cannot represent instances of util.Date):

use com\amazon\aws\ServiceEndpoint;
use util\Date;

$endpoint= new ServiceEndpoint(...);
$status= $endpoint->resource('/messages')
  ->transmit(['content' => 'Test', 'date' => Date::now()])
  ->status()
;

Unmarshalling response payloads

We can now add a result type to value(), result() and error() to which we want the response payload unmarshalled:

use com\amazon\aws\ServiceEndpoint;
use com\example\InvocationResponse;

$endpoint= new ServiceEndpoint(...);
$invocation= $endpoint->resource('/functions/greet/invoations')
  ->transmit(['name' => getenv('USER')])
  ->result(InvocationResponse::class)
;