#community-help

API Casing in Typesense and Dotnet Client Code

TLDR satish sought clarification on API casing standards. Jason explained that Typesense API uses snake_case, while the dotnet client code uses camelCase. Rune further elaborated on how to override the default properties in dotnet.

Powered by Struct AI
4
19mo
Solved
Join the chat
Apr 04, 2022 (19 months ago)
satish
Photo of md5-21068ce5c0a7db9d103fad551dbefbc7
satish
04:38 PM
What is the casing followed in API, Is that a snake case or Camel casing? I am looking at dotnet client code and its using camel casing but the docs shows snake case
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:05 PM
The Typesense API itself uses snake_case for API params. So the client might be translating from camel case to snake case before sending to Typesense.

CC: Rune who authored the dot net client
Rune
Photo of md5-a5a4aaa05c3354be4cd94c3d525ff5d7
Rune
06:08 PM
satish It uses camelCase by default, but you can override it on the document classes you want to insert into Typesense, here is an example:
[JsonPropertyName("house_number")]
public int HouseNumber { get; set; }

So you can set the names to whatever you like. 🙂
You could also do something weird like:
[JsonPropertyName("hOuse_NumBer")]
public int HouseNumber { get; set; } 

Full class example using snake_case:
public class Address
{
    [JsonPropertyName("id")]
    public string Id { get; set; }
    [JsonPropertyName("house_number")]
    public int HouseNumber { get; set; }
    [JsonPropertyName("access_address")]
    public string AccessAddress { get; set; }
    [JsonPropertyName("metadata_notes")]
    public string MetadataNotes { get; set; }
}

Also all API params are translated to snake_case if you use the default implementation shown in the docs, example doing a search.
var query = new SearchParameters("Smed", "access_address");
var searchResult = await typesenseClient.Search<Address>("Addresses", query);
Apr 05, 2022 (19 months ago)
satish
Photo of md5-21068ce5c0a7db9d103fad551dbefbc7
satish
02:10 AM
Thanks Rune.