Roy Prins
Roy Prins

Reputation: 3080

Combining django-rest-framework with regular HTTP application

I am reworking an application since it would benefit from having a RESTful backend. I feel that I have somehow taken a wrong turn by combining the rest API and the regular HTTP into a single app.

This means they share the urls.py and the views.py and are competing for urls and stuff gets mixed up (like applying the format_suffix_patterns to all urls).

I hope to get an opinion (or confirmation) that it would be a much better plan to roll it into two separate applications.

old plan

manage.py
/project
/combinedapp
    admin.py
    models.py
    urls.py       # both types of urls
    views.py      # both views

new plan

manage.py
/project
/restapp
    urls.py      # only the rest endpoints
    views.py     # api stuff: links to httpapp.models
/httpapp
    admin.py     # like a normal app
    models.py
    urls.py
    views.py

As you can tell I am new to this and trying to prevent shooting myself in the foot.

Upvotes: 2

Views: 422

Answers (1)

Roy Prins
Roy Prins

Reputation: 3080

I decided to refactor the project following the new plan. These are the results:

  • It was very easy to do: approximately 15 minutes of work to make a new app, move some files and split to content.
  • Protip: the new app is for the rest api. That way you conserve the existing table names and such.
  • Results are just fine: clear separation of concerns and urls.

Conclusion never mix a rest-api with an HTTP app.

Upvotes: 3

Related Questions