Charlot
Charlot

Reputation: 151

How to design an api to be called by different applications

Application A has an api setAge(String staffName). Application B and C both call this api. If a staff Jack has different names in A, B, C: JackA, JackB, JackC, so how to design application A to map JackB=>JackA and JackC=>JackA?

Upvotes: 0

Views: 69

Answers (1)

nansen
nansen

Reputation: 2952

You need to model identity in some way. If your business objects (e.g. staff members) are persisted in a relational db you can use the table's primary key, but this is a rather bad practice, as technical keys should not be relied upon on the application level. Instead use a unique business-id for your entities. That can be a String or a UUID for example. When accessing the entities in your API, clients have to pass that business-id as a parameter.

If you are in an OO language like Java, you might have to consider implementing object equality through equals and hashCode contracts (see here).

Upvotes: 1

Related Questions