0

I want to know the pros and cons of passing method parameter as object vs passing Json in context of AspNetCore WEB/REST API. For my application, ASPNET REST API is done in C#, clients are python. I suspect for interoperability, Json is better.

Example,

[HttpPost]
[Route("api/[controller]/SubmitBatchRequestJsonWay")]
public void SubmitBatchRequest(string jsonBatchRequest)
{
    return;
}

[HttpPost]
[Route("api/[controller]/SubmitBatchRequestPassPoco")]
public void SubmitBatchRequest2(SomeRequest req)
{
    return;
}

But i'm not sure if i am missing anything here?

Thanks

Passing Object as an parameter in Web Api How to pass object as parameter in Web Api

9
  • What are you asking? Can you give examples? Commented Nov 9, 2018 at 2:05
  • Wait...you do understand that ASP.NET Core will deserialize JSON to an object, right? Perhaps you should read "Create a Web API with ASP.NET Core and Visual Studio" on Microsoft's docs site? Commented Nov 9, 2018 at 2:10
  • 1
    How are JSON strings "better interop"? I really don't understand that part. Doesn't the client send JSON in either case? Aren't you just taking control from the framework deserializing your JSON and moving the deserialization to your controller method? I'm not sure why you want to make more work for yourself. Commented Nov 9, 2018 at 2:30
  • 1
    See my previous comment: "Wait...you do understand that ASP.NET Core will deserialize JSON to an object, right?" - ASP.NET Core does not accept some binary form of your C# class. It will deserialize JSON into a C# class. You do not have to do this manually. Commented Nov 9, 2018 at 2:36
  • 1
    ASPNET deserialize JSON into POCO-- thanks didnt know Commented Nov 9, 2018 at 2:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.