Hello, I have a question about FFI support for add...
# general
b
Hello, I have a question about FFI support for adding extra information in the request metadata. We have 2 pactipants that communicate using synchronous interactions via websockets (for which we use a pact plugin). The initial connection request requires extra metadata, which is added in the contract as part of the
request.metadata
field. This has worked fine for a RUST consumer, but I am struggling to replicate this using the FFI. Will give more details in thread.
Here is a sample snippet of the contract generated by the Rust consumer. Note the additional
path
entry in the
request.metadata
(required for establishing the initial connection):
Copy code
...
   "request": {
        "contents": {
            ...
        "metadata": {
          "contentType": "application/json",
          "path": "/jsonrpc"
        }
   ...
The consumer achieves this by making use of the
contents_from
, along the lines of:
Copy code
let mock_server = pact_builder
        .synchronous_message_interaction("sync message example", |mut i| async move {
            i.contents_from(json!({
                "pact:content-type": "application/json",
                "request": {
                    "query": "matching(equalTo, 'getTheData')"
                },
                "requestMetadata": {
                    "path": "/jsonrpc"
                    },
                },
                "response": [{
                    "data": "matching(equalTo, 'The data')"
                }]
            }))
    ...
For the FFI consumer I am using
pactffi_new_sync_message_interaction
and the
pactffi_
methods that work with
InteractionHandle
. Ideally I would like to achieve the same thing using the FFI, but I could not identify an API that would allow this. Can someone advise if it is possible to achieve this using the current FFI API? Or is this something that is missing and needs to be added?
j
Interesting that you have asked this now! I believe I created a PR to address this exact issue very recently: https://github.com/pact-foundation/pact-reference/pull/439. It adds a new
with_metadata
FFI for the
InteractionHandle
in order to set additional metadata for either the request or response. Is that what you're looking for? As it has only just been merged recently, there hasn't been a release yet, but you should be able to try it out by building the FFI library from dev if you want 🙂
🙌🏻 1
b
Wow, merged only 3 days ago 🙂 It really looks like what I am after. Would you know if there is a release planned any time soon?
j
There are a couple of other changes which I would like to introduce to the FFI, but I think these should be ironed out by early next week. After which, a release should be available soon after. So hopefully Tuesday or Wednesday?