Hello
I´m trying to define a standard for my API. Every resource I have right now, comes from a SQL Server Database. And most of them, are tables with a composite primary key.
Every resource has a href property pointing to itself, but i also need to complete an Id property to be able to identify it.
As they have composite keys, I thougth of setting the id property with the json value of the key object, for example:
Lets say just a silly example just to be more clear of a city resource:
City Table: countryId, provinceId, zipcode, name. PK = countryId, provinceId, zipcode
City Resource:
{
"href":"some link over here..",
"id":[
1,
3,
"2456ZC"
],
"countryId":1,
"provinceId":3,
"zipCode":"2456ZC",
"name":"Some City Name"
}
Then, when I get in the server this resource, I can use the id object to get the entity of the database by key.
Because the json Id property is pretty complex, I thought of serializing it in the server to json: [1,3,"2456ZC"]
And encode it with base64 url safe giving this result: WzEsMywiMjQ1NlpDIl0%3D
Final result:
{
"href":"https://api.com/cities/WzEsMywiMjQ1NlpDIl0%3D",
"id":"WzEsMywiMjQ1NlpDIl0%3D",
"countryId":1,
"provinceId":3,
"zipCode":"2456ZC",
"name":"Some City Name"
}
Is there any drawbacks of this solution? I know that if I add or remove one field of the primary key fields in the table the Id would change, but this would not happen.