RestEase icon indicating copy to clipboard operation
RestEase copied to clipboard

HTTP-Post - Collection Expresssions - Data will not be sent/serialized

Open rizi opened this issue 10 months ago • 7 comments

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

rizi avatar Mar 10 '25 10:03 rizi

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?

canton7 avatar Mar 15 '25 15:03 canton7

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

rizi avatar Mar 15 '25 15:03 rizi

What version of Newtonsoft.Json are you using?

canton7 avatar Mar 15 '25 16:03 canton7

What version of Newtonsoft.Json are you using?

I'm using 13.0.2

Br

rizi avatar Mar 15 '25 16:03 rizi

How odd, looks like it should work fine: https://dotnetfiddle.net/CzRxST``

canton7 avatar Mar 15 '25 17:03 canton7

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}]

canton7 avatar Mar 15 '25 17:03 canton7

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

rizi avatar Mar 15 '25 17:03 rizi