Building Separate Front-End for Mobile and Computer

36 views
Skip to first unread message

Day-V

unread,
Mar 26, 2012, 6:42:03 PM3/26/12
to pylons-discuss
I'm learning python with pyramid and MongoDB. I have prior code
experience, so learning Python has been really easy (love it!), the
documentation for Pyramid is incredible as well.

In summary, I want to build a python-based API which performs all
tasks and responds with JSON objects, and then use pyramid to connect
to the python-based API for I/O. Depending on device-type, I would use
different views.

My goal is to write a set of functions making up an API for my
application. Using Pyramid I would like to be able to build separate
front-ends that access the same, single API, so that I'm writing
functionality into one python-based core, and just returning views
that are applicable to whatever device type is accessing (phone,
tablet, computer).

Can anyone provide me with tips for the best way to accomplish this,
or links to any blog or forum posts that may already cover this?

Thanks for your help!
Davey

Jonathan Vanasco

unread,
Mar 27, 2012, 10:27:50 AM3/27/12
to pylons-discuss
Do you mean a JSON web API? If so , sounds like you're talking about
a Service Oriented Architecture.

To be honest, the *easiest* JSON APIs i've ever written were in Pylons/
Pyramid. You have full control of the request, and all you need to do
is return a dict from a view/handler that is decorated to render
json(p).

In terms of your app structure:

1) The @view_config decorator is pretty powerful and lets fine-tune
the scenarios in which a view is rendered. ( I wanted to write
'context' in there, but there is an argument to the constructor called
'context' with a pyramid-specific meaning ). You could conceivably
have a single codebase that just responds with different templates and
available methods.

2) I wouldn't have Pyramid call a Web API to process the data quite
yet. That's typically something you do at scaling time because it has
quite a bit of overhead in administration and maintenance. I'd
probably just construct the public web-based API methods to wrap some
helper functions into a package in app/lib that does the real work --
and which the webapp directly calls as well -- having them return
dicts. when you're ready to scale, you just have to change where you
request the dicts -- or how they're generated.

There are a handful of posts in this list and stackoverflow that talk
about customizing views for devices.

Day-V

unread,
Mar 27, 2012, 3:10:49 PM3/27/12
to pylons-...@googlegroups.com
Thank you, Jonathan! Excellent reply, and very helpful!
Reply all
Reply to author
Forward
0 new messages