Pakyow as an API framework

32 views
Skip to first unread message

nathan

unread,
May 15, 2012, 10:48:17 AM5/15/12
to pak...@googlegroups.com
I have the need for a lightweight api framework for a mobile application. I know most Rails folks use Sinatra for apis (like Github famously does), but I  would like to use Pakyow as my api framework.
 
I noticed in section 10.5 of the manual http://pakyow.com/manual#section_10.5 that Pakyow can respond to JSON requests. One way to implement the API, to check the request type each time. And respond with JSON. But this would mix my web server code with api code.
 
I would like a seperate Pakyow api application that only responds to JSON requests. Does Pakyow have a configuration option to do this or will I need to check the request type each time in the controller?
 
Is there a better approach to using Pakyow as an API server? Something I've overlooked? 
 
Thanks!
 
nathan
 

Bret Young

unread,
May 15, 2012, 11:04:15 AM5/15/12
to pak...@googlegroups.com

You haven't really overlooked anything. Currently, as you noted in the manual, you get the format in the request and then it's up to you how to handle that. I have thought about this a little and have various competing ideas on how to make this better. I'd love to hear any ideas you have on how you would like to see this expressed.

In the meantime, you could think about using a hook that reroutes all JSON requests to some other route, perhaps related to the original route. Something like that could separate the JSON stuff from the HTML stuff instead of mixing then in the same controller, as you mentioned. I'm not sure if this will work well for your case but something to think about.

Bret

Bryan Powell

unread,
May 15, 2012, 12:15:40 PM5/15/12
to pak...@googlegroups.com
Another approach would be to have a separate application for the api that uses the same models/database. You could run them side-by-side, for example one at mywebapp.com and the other at api.mywebapp.com. But, this wouldn't handle the case where you want the same paths (e.g. mywebapp.com/foo and mywebapp.com/foo.json) routed to different applications based on the request type. The approach Bret mentioned would work well for that case.

Bryan

nathan claburn

unread,
May 15, 2012, 2:05:50 PM5/15/12
to pak...@googlegroups.com
Yeah, the separate app is the approach I wanted to take. I just wanted to verify that I was going in the right direction and not missing something obvious.

Bryan Powell

unread,
May 15, 2012, 2:08:00 PM5/15/12
to pak...@googlegroups.com
Cool. Let me know how it works out!
Reply all
Reply to author
Forward
0 new messages