Consuming a RESTful API with Django

django, django-models, python

Solution

The `requests` library makes it easy to write a REST API consumer. There is also a Python library called `slumber`, which is built on top of `requests`, for the explicit purpose of consuming REST APIs. How well that will work for you likely depends on how RESTful the API really is.

Problem

I'm building a Django application that needs to interact with a 3rd party RESTful API, making various GETs, PUTs, etc to that resource. What I'm looking for is a good way to represent that API within Django. The most obvious, but perhaps less elegant solution seems to be creating a model that has various methods mapping to webservice queries. On the other hand, it seems that using something like a custom DB backend would provide more flexibility and be better integrated into Django's ORM. Caveat: This is the first real project I've done with Django, so it's possible I'm missing something obvious here.

Original source