Resources and naming
Name resources with nouns, not verbs. Use plural collection names and stable identifiers. Relationships can be nested when the child only makes sense within the parent, but deep nesting makes routes brittle and permissions harder to reason about.
Keep the response shape consistent. If a collection returns an object with data and pagination metadata, every collection should follow the same pattern. Consistency is more valuable than a clever one-off.
- Nouns for resources, HTTP methods for actions
- Stable identifiers and consistent casing
- Nesting only where the relationship requires it
- Consistent collection and error envelopes
Methods, status codes and validation
Use GET for reads, POST for creation, PATCH or PUT for updates and DELETE for removal. Return the status code that describes what happened: 201 for creation, 204 for an empty success, 400 for invalid input, 401 for missing authentication, 403 for insufficient permission and 404 for a missing resource.
Validate every input at the server, including fields the UI does not expose. Validation errors should identify the field and explain what is wrong. Do not rely on the client to enforce business rules.
- Correct method and status code for each operation
- Server-side validation for all input
- Field-level validation messages
- No sensitive data in URLs or logs
Versioning, documentation and limits
Version the API when a change cannot be made safely in place. Announce deprecations with a migration path instead of switching behaviour silently. Document the resources, authentication, request fields, responses and error codes.
Add rate limits where abuse or accidental load is possible. Log requests with enough context to debug them, but keep secrets and personal data out of the logs.
- A versioning and deprecation policy
- Endpoint reference kept current
- Rate limits and abuse protection where needed
- Structured logs without secrets
Key takeaways
- Predictability beats cleverness in an API contract.
- Validate and authorize on the server, every time.
- Use consistent error shapes and status codes.
- Version breaking changes and document the migration path.
Need help
Related services.
API Development
REST APIs that connect websites, applications, integrations and third-party services.
Backend Development
Server-side systems for authentication, data, business rules, integrations and background work.
PHP & Laravel Development
PHP and Laravel back-ends for content platforms, portals, integrations and business systems.
Questions
About this guide.
Should an API return JSON only?
JSON is the default for most web and mobile clients. Other formats can be supported when a consumer needs them, but the primary contract should stay consistent.
How many status codes should an API use?
Use the ones that describe the outcome accurately. A small, consistent set is easier to document and consume than a different code for every edge case.
When should an API be versioned?
When a change would break existing consumers and cannot be made backward-compatible. Additive changes can often ship without a new version; removals and shape changes usually cannot.