Closed cetindogu closed 4 years ago
In the past I had always used POST object for complex search query, so I don't need to worry the 2048 byte query limit. Anyway, are you happy with such generated codes?
/// <summary>
/// GET api/SuperDemo/AthletheSearch?take={take}&skip={skip}&order={order}&sort={sort}&search={search}
/// </summary>
public string AthletheSearch(System.Nullable<int> take, int skip, string order, string sort, string search)
{
var requestUri = "api/SuperDemo/AthletheSearch?" + (take.HasValue ? "take=" + take.Value.ToString() : "" ) + "&skip=" + skip + (order == null ? "" : "&order=" + Uri.EscapeDataString(order)) + (sort == null ? "" : "&sort=" + Uri.EscapeDataString(sort)) + (search == null ? "" : "&search=" + Uri.EscapeDataString(search));
var responseMessage = this.client.GetAsync(requestUri).Result;
try
{
responseMessage.EnsureSuccessStatusCodeEx();
var stream = responseMessage.Content.ReadAsStreamAsync().Result;
using (System.IO.StreamReader streamReader = new System.IO.StreamReader(stream))
{
return streamReader.ReadToEnd(); ;
}
}
finally
{
responseMessage.Dispose();
}
}
Also, for TS client, what do you expect the behavior of different string value. In C#, a string parameter value could be:
In JS/TS
Apparently null and undefined could be considered as undefined. And a simple way to check isNullOrUndefined is mentioned by mar10 @ https://stackoverflow.com/questions/2559318/how-to-check-for-an-undefined-or-null-variable-in-javascript
Are you happy with that?
released 3.11.3
My Web Api Method Signature; [HttpGet] IEnumerable AthletheSearch(int? take = 10, int skip = 0, string order = null, string sort = null, string search = null);
Auto Generated method's first line var requestUri = new Uri(this.baseUri, "api/Athlethe?"+(take.HasValue?"take="+take.Value.ToString():String.Empty)+"&skip="+skip+"&order="+Uri.EscapeDataString(order)+"&sort="+Uri.EscapeDataString(sort)+"&search="+Uri.EscapeDataString(search));
THROWS ERROR: ArgumentNullException: Value cannot be null. (Parameter 'stringToEscape') System.Uri.EscapeDataString(string stringToEscape)
when i used in my ASPNET CORE 3.1 MVC project client; HttpClient client = new HttpClient(); Uri uriBase = new Uri("https://localhost:44314/");