I have an API to find data, and this how it looks : "/api/v1/ProjectList/find"
The BE will create this link with 1 field to search
http://localhost:8081/api/v1/ProjectList/find?fields=Id&values=10&types=Int32&operators=%3D
and this link with 2 or more fields
http://localhost:8081/api/v1/ProjectList/find?fields=Id&fields=Name&values=10&values=Test&types=Int32&types=string&operators=%3D&operators=%3D
I have GetMethod() to get my List.
public List<T> GetMethod<T>(string uri, Dictionary<string, string> headers = null)
{
var client = new RestClient(uri);
var request = new RestRequest(uri,Method.Get) { RequestFormat = DataFormat.Json };
var result = GetResult<T>(client, request, null, headers);
return result;
}
private List<T> GetResult<T>(RestClient client, RestRequest request, object requestObject = null, Dictionary<string, string> headers = null)
{
if (headers != null)
{
foreach (var header in headers)
{
request.AddHeader(header.Key, header.Value);
}
}
if (requestObject != null)
{
request.AddJsonBody(requestObject);
}
request.AddHeader("authorization", $"bearer {SettingsModule.CurrentUser.AccessToken}");
var response = client.Execute(request);
//ar jObject = JObject.Parse(response.Content);
return JsonConvert.DeserializeObject<List<T>>(response.Content, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
But I don't know how to insert these fields inside the URI with parameters. and how to call it inside the URI.
const string uri = "http://localhost:8081/api/v1";
IApiService client = new ApiServiceRestSharp();
var getUri = $"{uri}/{"MdBenefitMain/find"}";
var a = client.GetMethod<MdBenefitMain>(getUri);
What is missing from my code to use find API? and 1 more question, if the sort order should applied or not?