DEV Community

DEVANSHU PATIL
DEVANSHU PATIL

Posted on

Your API Is a Contract, Not Just a URL

Your API Is a Contract, Not Just a URL

When I started working with backend APIs, it was easy to think of an API as simply:

GET /users
POST /transactions
DELETE /transactions/:id
Enter fullscreen mode Exit fullscreen mode


`

The endpoint works, the frontend gets data, and the job seems finished.

But as an application grows, the API becomes something much more important.

It becomes a contract between different parts of the system.

For example:

text
Android App

API

Backend

Database

The Android application shouldn't need to know how the backend stores its data.

It only needs to know what the API promises to provide.

A response is part of the contract

Suppose an endpoint returns:

json
{
"id": 42,
"name": "Rahul",
"amount": 5000
}

The client starts depending on that structure.

Now imagine the backend changes:

json
{
"transactionId": 42,
"personName": "Rahul",
"totalAmount": 5000
}

The backend may still work perfectly.

But the Android application can break.

That's why API changes aren't just backend changes.

They can be system-wide changes.

Consistency matters

An API becomes much easier to work with when similar operations behave similarly.

For example:

text
GET /transactions
GET /transactions/:id
POST /transactions
PUT /transactions/:id
DELETE /transactions/:id

The exact design can vary, but predictable conventions reduce the amount of knowledge the client needs.

The same applies to errors.

Instead of returning completely different structures:

json
{
"error": "Something went wrong"
}

and somewhere else:

json
{
"message": "Invalid transaction"
}

a consistent error format is much easier for clients to handle.

For example:

json
{
"error": {
"code": "INVALID_TRANSACTION",
"message": "Transaction amount must be greater than zero"
}
}

Now the Android application can make decisions based on a predictable structure.

Don't expose your database blindly

Another thing I'm learning is that an API response doesn't have to look exactly like the database row.

Your database might contain internal fields that the client doesn't need.

For example:

text
Database model

Repository

Service / business logic

API response model

This separation gives you freedom to change your database without automatically changing your public API.

That's especially important as the project grows.

Validation belongs on the backend too

Client-side validation improves the user experience.

But it shouldn't be your only line of defense.

If the Android application checks:

text
amount > 0

the backend should still validate it.

Why?

Because an API can be called by something other than your Android application.

The backend should assume that incoming data is untrusted.

text
Client validation
+
Backend validation
+
Database constraints

Each layer provides another level of protection.

Think about failure, not only success

When designing an endpoint, it's easy to think:

"What happens when everything works?"

A better question is:

"What happens when it doesn't?"

What if:

  • The requested record doesn't exist?
  • The user isn't authorized?
  • The input is invalid?
  • The database is unavailable?
  • The client sends an unexpected value?
  • The request is repeated?
  • The network fails halfway through?

Good API design includes these cases from the beginning.

The bigger lesson

An API is not just a collection of endpoints.

It's the boundary between systems.

Once an Android application, web application, or another service starts depending on it, changing that boundary carelessly becomes expensive.

So I'm starting to think about APIs less like:

text
"Which endpoint do I need?"

and more like:

text
"What contract should this system expose?"

That shift changes how you design requests, responses, errors, validation, authentication, and versioning.

And the more systems you connect together, the more important that contract becomes.

**A good API doesn't just make communication possible.

It makes communication predictable.**

api #backend #android #kotlin #softwareengineering #systemdesign #webdevelopment #buildinpublic

`

Top comments (0)