Reputation: 107102
What are the pros and cons for using django related REST API packages such as tastypie, piston or django-rest for non-ORM calls over simply using views?
Upvotes: 0
Views: 492
Reputation: 92567
I don't think its really a question of whether the API resources directly map to models or not. Its a matter of these API packages abstracting away much of the boilerplate code that you end up doing like checking the request type, mapping to URLs, and serializing your output. Associating a resource with a model is simply one of many features, allowing you to more easily format the representation of the data.
While I can't really see this as an significant negative, I suppose using an API package does require you to conform to its specs and generally work within the realm of its features. But packages like piston or tastypie are so convenient, I can't really think of a real reason NOT to use them if your goal is to expose a RESTful api. You get so much for free. These packages also tend to include extra authentication functionality, and decorators.
Writing basic django views is just the same as rolling your own API. Either use a package for convenience, or roll your own if you really need something custom that they don't provide.
Upvotes: 1
Reputation: 107102
Besides REST to ORM call translations, many aspects can be handled for you by a good API package, such as being able to support multiple serialization backends, handling of authentication/authorization, caching, throttling and more.
If you don't expect your project to ever need these benefits in the future, going for hard coded views may be the quickest, however that tends not to be the case.
Upvotes: 0