HTTP-Post - Collection Expresssions - Data will not be sent/serialized
Description We have the following definition of an api-endpoint:
Task TransferFormatsAsync([Body] IReadOnlyCollection<ProductionManagerFormat> formats);
When we call this endpoint, like this (with collection expressions) we get 200 OK, but in the web server logs I can see that RestEase is not sending a body (it's empty):
await _api.TransferFormatsAsync([new ProductionManagerFormat("A4", 200, 300)];
To Reproduce
public interface IProductionManagerApi
{
[Post("api/TransferFormats")]
Task TransferFormatsAsync([Body] IReadOnlyCollection<ProductionManagerFormat> formats);
}
e.q in a controller call the api:
public void MyController (IProductionManagerApi _productionManagerApi) : ApiController
{
[HttpGet]
async Task TestAsync()
{
await _productionManagerApi.TransferFormatsAsync([new ProductionManagerFormat("A4", 200, 300)]);
}
}
Version Info
- RestEase version: 1.6.4
- Target framework version: .net 9
That should work fine.
with collection expressions
Is the implication that it works fine if you don't use a collection expression?
Are you using a custom RequestBodySerializer?
That should work fine.
with collection expressions
Is the implication that it works fine if you don't use a collection expression?
Are you using a custom
RequestBodySerializer?
It's working fine without collection expression, I don't use a custom serializer.
I will double check and report back, thx for the response!
Br
What version of Newtonsoft.Json are you using?
What version of Newtonsoft.Json are you using?
I'm using 13.0.2
Br
How odd, looks like it should work fine: https://dotnetfiddle.net/CzRxST``
I can't repro either.
public class Program
{
public static async Task Main()
{
var productionManagerApi = RestClient.For<IProductionManagerApi>("https://czavrgjz1wg00003kdpggxiphcyyyyyyn.oast.pro");
await productionManagerApi.TransferFormatsAsync([new ProductionManagerFormat("A4", 100, 200)]);
}
}
public interface IProductionManagerApi
{
[Post("api/TransferFormats")]
Task TransferFormatsAsync([Body] IReadOnlyCollection<ProductionManagerFormat> formats);
}
public record ProductionManagerFormat(string Name, int Width, int Height)
{
}
Gives the request (captured by requestbin.net):
POST /api/TransferFormats HTTP/1.1
Host: czavrgjz1wg00003kdpggxiphcyyyyyyn.oast.pro
Content-Length: 40
Content-Type: application/json; charset=utf-8
[{"Name":"A4","Width":100,"Height":200}]
I can't repro either.
public class Program { public static async Task Main() { var productionManagerApi = RestClient.For<IProductionManagerApi>("https://czavrgjz1wg00003kdpggxiphcyyyyyyn.oast.pro"); await productionManagerApi.TransferFormatsAsync([new ProductionManagerFormat("A4", 100, 200)]); } }
public interface IProductionManagerApi { [Post("api/TransferFormats")] Task TransferFormatsAsync([Body] IReadOnlyCollection<ProductionManagerFormat> formats); }
public record ProductionManagerFormat(string Name, int Width, int Height) { } Gives the request (captured by requestbin.net):
POST /api/TransferFormats HTTP/1.1 Host: czavrgjz1wg00003kdpggxiphcyyyyyyn.oast.pro Content-Length: 40 Content-Type: application/json; charset=utf-8 [{"Name":"A4","Width":100,"Height":200}]
Thx for trying, as soon as I'm in the office I will try it on my end,maybe it was something else and just looked like it's related to collection expressions.
Br