Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
Python & Django

Serving Other Systems From a Django Application

Last updated:

Share the logic, not the views

The temptation is to duplicate business rules between web views and API endpoints. That duplication drifts, and the two paths eventually behave differently.

Put the business logic in a service layer that both the web views and the API call. Then a rule change applies everywhere by construction.

Permissions must apply identically

  • The same record-level filtering as the web interface
  • The same action permissions
  • Tested adversarially, with tokens from different users
  • Applied to list endpoints, not just detail ones

An API that bypasses your permission model is a hole in it, and it is frequently discovered by someone exploring rather than by a test.

Design for the consumer

  1. Consistent structure across every endpoint
  2. Meaningful status codes, not 200 with an error in the body
  3. Pagination on every collection, from the start
  4. Filtering and ordering where consumers will need it
  5. Expose business concepts, not your table structure

Version it from the beginning

Adding versioning after the first consumer means either breaking them or maintaining an unversioned path forever. A path prefix costs nothing at the start.

Then be explicit about what constitutes a breaking change and announce deprecations with real dates.

Rate limit, including internally

LimitApplies to
Per tokenExternal consumers
Per endpointExpensive operations
Internal servicesYes — loops cause outages
Unauthenticated endpointsStrictly

Frequently asked questions

Should we use a REST framework?

For anything beyond a couple of endpoints, yes. Serialisation, permissions and pagination are solved problems.

How do we handle authentication?

Tokens for services, session or token for a first-party front end. Do not invent a scheme.

Can the API and web app share models?

Yes, and they should share the service layer too. Duplicating business rules between them is the failure to avoid.

What about documentation?

Generated from your serialisers and schemas, so it cannot drift from the implementation.

Keep reading

Adding an API to an existing application?

The permission and logic sharing decisions matter most. Happy to review a design.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Custom Software DevelopmentWeb DevelopmentMachine Learning