1

Flurl doest not format query params based on newtonsoft json namin strategy like body content does, so I created a base class for translate it.

public abstract class FlurlBaseQueryParam
{
    public Dictionary<string, string> ParseQueryParams()
    {
        var stringParams = JsonConvert.SerializeObject(this, settings: new JsonSerializerSettings()
        {
            NullValueHandling = NullValueHandling.Ignore
        });
        return JsonConvert.DeserializeObject<Dictionary<string, string>>(stringParams, new KeyValuePairConverter());
    }
}

Then you can inherit and apply the naming strategy for each object as follows in the example below.

  • CamelCaseNamingStrategy
  • SnakeCaseNamingStrategy
  • KebabCaseNamingStrategy
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class GetByParamRequest : FlurlBaseQueryParam
{
    public string Identification { get; set; }
    public string Email { get; set; }
}

And then you should call the ParseQueryParams method inside the SetQueryParams method, as follows.

public async Task<ResponseModel> GetByParamAsync(GetByParamRequest request)
{
    try
    {
        return await Url.SetQueryParams(request.ParseQueryParams())
            .GetJsonAsync<ResponseModel>();
    }
    catch (FlurlHttpException e)
    {
    }

    return new ResponseModel();
}
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 24 '22 at 15:55
  • It is not a question, it is a solution for FLURL query param be formated as naming strategy defined. – Renan Carvalho Ribeiro Mar 24 '22 at 16:23
  • I’m voting to close this question because it is not a question, but rather than an answer. Please [edit] your question to pose a question, then post the solution as an answer. – Jeremy Caney Mar 25 '22 at 02:04

0 Answers0