How do I prepare a DTO in JS to be send via GET request?

Hello,

I have a request DTO in form

public class MyItem
{
	public string Name { get; set; }
	public int Count { get; set; }
}

[Route("/test2")]
public class TestCollectionDTORequest : IReturnVoid
{
	public IList<MyItem> Items { get; set; }
}

What is a right way to send it from javascript using GET request?

Please don’t use interfaces in DTO’s, use a concrete List<T> instead. IList<T> is especially useless since it’s almost always hiding a List<T>.

You can send complex types on the QueryString using the JSV Format which would look like:

/test2?items={Name:foo,Count:1},{Name:bar,Count:2}

But ideally your Request DTO’s should be flat for most interoperability and not require passing complex types on the QueryString.

Thank you. Do you know which tools in Javascript (in jQuery) can create this query given an object?

There’s no support for sending complex types on the query string with popular JS libraries as its not recommended practice.

The JSV.js provides a JSV implementation in JavaScript which lets you serialize JSV with JSV.stringify(). But I’d be looking at redesigning your Service so this isn’t needed.

GET requests should be flat so they’re easily accessible by different HTTP libraries, clients, command-line utils, etc. You may want to instead consider sending a POST request instead.

Thank you. We probably will follow your advise and change the verb to POST.