-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pact consumer API is incompatible with the Refit client #424
Comments
Why does it send an empty body? Bodies on GET requests are not supposed to be a thing (especially if not requested by the client) |
You ask questions ^^ I don't know why they are doing that. I was supprised myself when I detected the different handling between Pact and Refit. |
@uglyog any thoughts/suggestions on how we could address this use case? |
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. |
I just tried it with a plain HttpClient. This sends Body: Empty as well. Am I doing something wrong? public async Task<ICollection<UserDto>> GetUsersAsync(GetUsersQueryParameters query, CancellationToken cancellationToken = default)
{
return (await _http.GetFromJsonAsync<ICollection<UserDto>>($"/users?UserIds={string.Join(",", query.UserIds)}", cancellationToken))!;
} My Pact definition: _pactBuilder!
.UponReceiving("A GET request to retrieve multiple users with existing ids 1, 2 and 3")
.Given("There exist a user for every provided id")
.WithRequest(HttpMethod.Get, "/api/s2s/users")
.WithQuery("UserIds", "1,2,3")
.WithHeader("accept", "application/json")
.WithHeader("host", Match.Type("127.0.0.1:56541"))
.WithHeader("traceparent", Match.Type("00-b7d5eb21662c741f992816792949f208-34ac459fb07586a2-00"))
.WithHeader("request-id", Match.Type("|b7d5eb21662c741f992816792949f208.34ac459fb07586a2."))
.WithHeader("Authorization", Match.Type("Bearer SomeValidAuthToken"))
.WillRespond()
.WithStatus(HttpStatusCode.OK)
.WithHeader("Content-Type", "application/json; charset=utf-8")
.WithJsonBody(.....); Driver logs:
|
I figured out what the final problem was: #420 This issue can be closed |
ah! 🤦 |
Hi there,
We are using Refit to generate typed API clients.
e.g.
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.The text was updated successfully, but these errors were encountered: