Pact consumer API is incompatible with the Refit client
See original GitHub issueHi 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:
- Created 10 months ago
- Comments:8 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
The FFI functions need to be updated to support passing in an empty body and content type