Skip to Content
0

Best approach on developing API Layer using Odata in HANA XS - Foreign Keys

Apr 24, 2017 at 01:25 PM

52

avatar image
Former Member

Hi Folks,

I am building a small application on HANA XS.

There is a question I have regarding APIs. I need validation if my approach is valid.

I have database tables similar to the below:

Table 1 :

ID - PK 
NAME - TEXT
COUNTRY - FK
STATE - FK
CITY - FK
ETHNICITY - FK

Table 2 :

ID - PK
COUNTRY - TEXT

Table 3 :

ID - PK
STATE - TEXT
COUNTRY_ID - FK

Table 4 :

ID - PK
CITY - TEXT
STATE_ID FK

Table 5 :

ID - PK
ETHNICITY - TEXT

Legend:

PK - Primary Key

FK - Foreign Key

Now using Odata in XS -

I can show this data by creating associations and using Expand option.

But to insert the data into table 1 :

1. I need to provide cascading drop downs with individual Odata.

2.Show the "VALUE" to the User in drop down and Propagate the Selection to next drop down (Country / State then City) .

3. Finally I will create a POST request with the KEY value for each of the selections from the drop down bindings.

4. Create a custom Modification exit in XS ODATA using XS LIB / XS JS and call it for UPDATE / INSERT.

This way I will have the same service which can do CRUD on single table but has columns referencing many other tables.

Is this the only way?

I was wondering how are APIs built for tables which have such multiple Foreign Key references to other Tables (Mostly might be cascading drop downs or Individual Drop downs ) and need to have a standard API.

If I follow this approach, however the API POST will have payload something like this :

{

"name" : "vyas",

"country" : "5" ,

"state" : "8",

"city" : "3" ,

"ethnicity" : "3"

}

If I let the VALUE be the actual value from the Drop down binding be passed. The POST will look like this.

{

"name" : "vyas",

"country" : "India" ,

"state" : "Maharashtra",

"city" : "Mumbai" ,

"ethnicity" : "Indian"

}

and then I have to look up the actual keys for each Property in the API modification exit and perform the Insert.

What should be the right way?

Is there some other better / recommended approach that I am not aware of.

Please suggest. :)

Thanks !

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers