API Design

API is an Application programming interface you define how a client can consume your service through a function than how you implemented.

As part of API design, you need to make sure you define the name of your endpoint/function clearly without any ambiguity, naming should be self-descriptive.

Let’s take a small example

https:// xyz . com /data/5

getMapping(“/data/{id}”)
List<Data> getData(@PathVariableString id){
}
try to reduce the API calls as much as possible. I/O is costly. by passing relevant information to the API in the payload

don’t include routing information in the payload let that be part of your Url itself
e.g
HttpBody:

{
action:”getData”,//bad design
id:”abc1"
}
Instead :xyz . com /data/getData/abc1
Define properly the error cases more specific than generic .instead of error 404 use id not found.

try to see you avoid the side-effects and atomicity problems with API

Side-effects sending more data than intended. define the API contracts such as response carefully.
Atomicity tries to define the API’s to subparts if it needs to perform more than the intended cause.
Don’t Overload clients with a huge response
use techniques like pagination/fragmentation to send a response that the client can handle at once as streams if possible

You also need to gather information about how consistent the data in API whether to consider cache/no-cache for an API call.

--

--