[Tutor] build a really simple "json" api from a db

Eric Brunson brunson at brunson.com
Mon Jul 30 23:39:00 CEST 2007


Picio wrote:
> The beginning idea was to build a json API myself. Since I need only
> to generate json from a db, maybe Django is too much. I'm a Django
> beginner. I don't know Turbogears.
> I've not found anything like: "how to build a json api".
> Maybe MySqldb+simplejson is the enough?
> Or
> Is It more simple to learn how to use Django to create a json api?
>   

Picio,

You seem to be in analysis paralysis.  You don't understand the 
underlying technology, which is making the task seem daunting.  Break it 
down into component parts and learn the ones you don't already understand.

It seems the most important aspects of the project are getting info out 
of the database, converting it to JSON and publishing it via HTTP.  Do 
you have a web server?  Then write the simplest example of a CGI script 
to query a database and serve serve it up using simplejson.   If you 
don't have a web server, then wrap it in a little CGIHTTPServer 
(http://docs.python.org/lib/module-CGIHTTPServer.html).

I'm not trying to criticize on you or make you mad, but if you'd jumped 
in and tried it out instead of posting here all weekend, you'd probably 
have a working prototype by now.  You'll probably go through 10 
different iterations before you have a final product and you'll be able 
to reuse any of the code you come up with.  Just do it and we'll help 
you with any questions you have along the way.

Go, go, go.  It's your birthday, you can do this.  :-)

e.

> 2007/7/28, Alan Gauld <alan.gauld at btinternet.com>:
>   
>> "Picio" <picioslug at gmail.com> wrote
>>
>>     
>>> Hello, I'd like to know the necessary steps to build a json api for
>>> two table on my db.
>>>       
>> Since you seem to be using Django are you sure that isn't built in?
>>
>> I use Turbo Gears and JSON is a standard feature turned on by
>> an option in a method. Django is quite similar to TG in most respects
>> so I'll be surprised if it can't do JSON directly.
>>
>>     
>>> I've seen this snippet on the djangosnippet site.
>>> http://www.djangosnippets.org/snippets/154/
>>> Is It the right way.
>>>       
>> If its on the Django web site and you are using Django then
>> probably! :-)
>>
>> It certainly looks like a recommendation to me.
>>
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.freenetpages.co.uk/hp/alan.gauld
>>
>>
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>     
>
>
>   



More information about the Tutor mailing list