Mimic remote API or extend existing django model

Posted by drozzy on Stack Overflow See other posts from Stack Overflow or by drozzy
Published on 2010-05-03T15:54:40Z Indexed on 2010/05/03 15:58 UTC
Read the original article Hit count: 388

Filed under:
|
|
|
|

I am in a process of designing a client for a REST-ful web-service.

What is the best way to go about representing the remote resource locally in my django application?

For example if the API exposes resources such as:

  • List of Cars
  • Car Detail
  • Car Search
  • Dealership summary

So far I have thought of two different approaches to take:

  1. Try to wrangle the django's models.Model to mimic the native feel of it. So I could try to get some class called Car to have methods like Car.objects.all() and such.
    This kind of breaks down on Car Search resources.
  2. Implement a Data Access Layer class, with custom methods like:

    • Car.get_all()
    • Car.get(id)
    • CarSearch.search("blah")

    So I will be creating some custom looking classes.

Has anyone encoutered a similar problem? Perhaps working with some external API's (i.e. twitter?)

Any advice is welcome.

PS: Please let me know if some part of question is confusing, as I had trouble putting it in precise terms.

© Stack Overflow or respective owner

Related posts about api

Related posts about best-practices