question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pact consumer API is incompatible with the Refit client

See original GitHub issue

Hi there,

We are using Refit to generate typed API clients.

e.g.

var httpClient = new HttpClient { BaseAddress = new Uri(ctx.MockServerUri, "/api") };
var client = Refit.RestService.For<IMyApiClient>(httpClient);

When I do a GET request with Refit, it will send a request with an empty body without any content-type header. Pact expects a missing body in this case. When I try to configure an expected empty body (with WithBody) to match it with the request Refit is doing, I am forced to set an expected content-type as well. With this constraint I can never make those two library work together.

2022-11-09T07:00:43.297948Z  INFO tokio-runtime-worker pact_mock_server::hyper_server: Received request HTTP Request ( method: GET, path: /api/s2s/users, query: Some({"UserIds": ["1,2,3"]}), headers: Some({"host": ["127.0.0.1:62466"], "request-id": ["|98394da7c0defc2670305f8a0e803693.040a6b8dbc244591."], "authorization": ["Any valid token"], "accept": ["application/json"], "traceparent": ["00-98394da7c0defc2670305f8a0e803693-040a6b8dbc244591-00"]}), body: Empty )
2022-11-09T07:00:43.298541Z  INFO tokio-runtime-worker pact_matching: comparing to expected HTTP Request ( method: GET, path: /api/s2s/users, query: Some({"UserIds": ["1,2,3"]}), headers: Some({"host": ["127.0.0.1:56541"], "request-id": ["|b7d5eb21662c741f992816792949f208.34ac459fb07586a2."], "accept": ["application/json"], "Authorization": ["Bearer SomeValidAuthToken"], "traceparent": ["00-b7d5eb21662c741f992816792949f208-34ac459fb07586a2-00"]}), body: Missing )

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lehmamiccommented, Nov 10, 2022

The FFI functions need to be updated to support passing in an empty body and content type

Another option would be that no body considers an empty body as well. Either way is ok.

Btw. I used this combination already before and it did not cause any problems. But this was with Pact V2.

1reaction
rholshausencommented, Nov 9, 2022

The FFI functions need to be updated to support passing in an empty body and content type

Read more comments on GitHub >

github_iconTop Results From Across the Web

FAQ | Pact Docs
You can find the answers to some more technical and complex questions here.
Read more >
Getting "an interaction with same description and provider ...
First, I had 1 pact test case set up and working perfectly. The setup was simple (using Jest):. beforeAll: create a new Pact()...
Read more >
Pact is dead, long live Pact - the future of contract testing
Whilst Pact significantly improves coupling with respect to integrated tests, it does have a level of coupling between consumers and providers, ...
Read more >
Troubleshooting | Pact Docs
Testing HTTP errors is straightforward with Pact, however most api clients (such as Axios) will throw if they receive a response code >=...
Read more >
Painless contract testing with Pactflow - kreuzwerker
The Pactflow broker uses the API specification file to check compatibility of both sides without the provider needing to accommodate the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found