How we design a CodeIgniter API that lasts
Agree the contract before coding
We write the endpoint list with the people who will consume it: paths, request bodies, response fields, error cases. That description, in OpenAPI format, becomes the shared reference. Mobile developers can generate mock responses and start work straight away, instead of waiting for the backend to be finished. It also exposes awkward screens early, such as a dashboard that would need nine calls, while changing the design costs nothing.
CodeIgniter 4 or CodeIgniter 3
For a new API we use CodeIgniter 4. ResourceController and the resource route method give a standard REST shape, the response trait handles status codes and formats, filters handle cross-cutting checks, and the Throttler class provides rate limiting without extra infrastructure. When the API must live inside a CodeIgniter 3 application, we add a REST controller library, keep API controllers in their own folder, and put shared logic in models or libraries so web and API paths cannot drift apart. Session-based checks are never reused for the API. Each API request authenticates by itself.
Authentication that fits the client
There is no single right token scheme. For your own mobile app, opaque access tokens stored hashed in the database are simple and can be revoked instantly when a phone is lost. Signed JWTs make sense once more than one service has to trust the same token and a lookup on every call is too slow. Pulling one back early is awkward, which is why ours expire quickly and are renewed through a refresh token. Partner integrations get keys tied to a client record with explicit permissions. Whatever the scheme, tokens travel in the Authorization header over HTTPS, and login endpoints are throttled more tightly than the rest.
Versioning from the first release
Mobile apps stay installed for years. We put the version in the route group from day one and treat a published response as frozen: fields may be added, never renamed or removed. A breaking change means a new version served alongside the old one, plus a way for the app to learn that it should update. This costs little at the start and is painful to retrofit.
Testing and observability
Every endpoint has feature tests covering the success case, validation failure, missing token and wrong permission. A Postman collection is kept for manual checks by your team. In production we log request IDs, response times and error rates per endpoint, so a slow query or a misbehaving client is visible before users complain. If your consumers include a larger product with queues and events, compare this with Laravel API development.