Whats the advantage of using a package to create a

2019-08-30 00:06发布

问题:

I am creating a simple RESTful interface on one of my apps and I have been looking at what's available out there:

I've looked at:

  • django-piston but it seems abandoned and the feedback on it is not great.
  • django-dynamicresponse which seems rather bare
  • A lot of packages from here

However, looking at examples of how these packages it seems that they don't really provide much. It's really not that hard to create a list of URL mappings and use something like simplejson to return a response...

Is there an advantage to using one of these packages that I am missing?

This question may be similar to Django and Restful APIs but it has been a while since that one had any new answers, and I want to find out whether it is worth to use a package at all.

Thanks

回答1:

If you are writing one API for one or two simple models for "internal" use (eg, for the AJAX frontend of your app to communicate with the backend vs. an API exposed to external clients), then frameworks like django-piston or Tastypie might be overkill compared to writing one or two views and using simplejson.

Where the frameworks start to really pull their own weight is when you have more complicated requirements. Some examples:

  • you have a complicated model with a lot of relations (think nested tree structures)
  • you need to support multiple serializations (XML, YAML, Plists, or JSONP in addition to JSON)
  • you want to version your API
  • you want to do restrict access for some operations (eg, to provide read-only access to certain clients)
  • you want to throttle or rate-limit client access

Many of those aren't a big deal on a small, simple project where you control both ends, but become very important when you're thinking about making an external API to your service.