API & Integrations

REST API Best Practices: Building APIs That Last

Practical REST API design principles that make your APIs reliable, maintainable, and easy to integrate with — from a business software perspective.

AK

Abraham Kariuki, Alpha Tec Solutions

Full-Stack Software Developer

·8 min read
Code annotation showing REST API URL structure, HTTP methods, and response format standards

Why API Design Matters for Business Software

Your API is the contract between your system and every other system it connects to. A poorly designed API creates integration headaches for years. A well-designed API becomes a business asset that enables growth.

According to Postman's 2025 State of the API report, 89% of developers say API quality directly impacts their ability to deliver projects on time.

Naming and URL Structure

Use Nouns, Not Verbs

✗ GET /getProperties
✗ POST /createTenant
✓ GET /properties
✓ POST /tenants

Building something similar?

See how we approach business software development.

Explore Our Solutions

The HTTP method IS the verb. The URL is the noun.

Use Plural Nouns for Collections

✓ GET /properties          — List all properties
✓ GET /properties/123      — Get property 123
✓ POST /properties         — Create a property
✓ PATCH /properties/123    — Update property 123
✓ DELETE /properties/123   — Delete property 123

Nest Resources Logically

✓ GET /properties/123/units           — Units for property 123
✓ GET /properties/123/units/456       — Unit 456 in property 123
✓ GET /tenants/789/leases             — Leases for tenant 789

✗ GET /getUnitsForProperty?id=123     — Avoid query-style URLs for resource hierarchies

Use Proper HTTP Methods

MethodPurposeIdempotentSafe
GETReadYesYes
POSTCreateNoNo
PUTFull replaceYesNo
PATCHPartial updateNoNo
DELETEDeleteYesNo

Response Format Standards

Always Return Consistent Structure

// Success response
{
  "data": { ... },
  "meta": {
    "total": 142,
    "page": 1,
    "perPage": 20
  }
}

// Error response
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Email address is required",
    "details": [
      { "field": "email", "message": "Required" }
    ]
  }
}

Use Proper HTTP Status Codes

200 — Success (GET, PATCH, PUT)
201 — Created (POST)
204 — No Content (DELETE)
400 — Bad Request (validation error)
401 — Unauthorized (not logged in)
403 — Forbidden (logged in but no permission)
404 — Not Found
409 — Conflict (duplicate resource)
422 — Unprocessable Entity (semantic validation error)
429 — Too Many Requests (rate limited)
500 — Internal Server Error

Pagination

Never return unbounded lists. Always paginate:

GET /properties?page=1&perPage=20&sort=createdAt&order=desc

Response:
{
  "data": [ ... ],
  "meta": {
    "total": 142,
    "page": 1,
    "perPage": 20,
    "totalPages": 8,
    "hasNext": true,
    "hasPrev": false
  }
}

Authentication and Security

Use Bearer Tokens

Authorization: Bearer eyJhbGciOiJIUzI1NiIs...

Rate Limiting

Always implement rate limiting to protect your API:

Response headers:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 87
X-RateLimit-Reset: 1640000000

Input Validation

Never trust client data. Validate everything server-side:

// Validate at the API boundary, not just in the UI
const createPropertySchema = z.object({
  name: z.string().min(1).max(200),
  address: z.string().min(1),
  units: z.number().int().min(1),
  type: z.enum(['residential', 'commercial', 'mixed']),
});

Versioning

Version your API from day one:

✓ /api/v1/properties
✓ /api/v2/properties  (when you need breaking changes)

✗ /properties  (no version = breaking changes break all clients)

TIP

Key Takeaways

  • URLs are nouns (plural), HTTP methods are verbs
  • Always return consistent response structure with data/meta or error
  • Use proper HTTP status codes — not just 200 and 500
  • Always paginate list endpoints
  • Implement auth, rate limiting, and input validation from day one
  • Version your API if external consumers will use it
SHARE THIS INSIGHT

Have a Business Problem Software Could Solve?

Tell us what you're trying to improve, automate or build.