i'll add a couple of comments:

 - if you define your models carefully with requires parameters 
(validators) in web2py, the SQLFORM object will use them, and you can 
trigger the use of those validators via your REST API (i forget the exact 
call, but there is something that does validation and insert/update in the 
recent releases of web2py)
 - if you have custom processing logic, you can always put it in modules 
and have your REST and your web form wrappers just call out to those 
modules for processing.

i think you can achieve a high level of code reuse if you plan your code 
carefully.  i assume the same would be true in flask as well.

good luck!

cfh

On Saturday, July 28, 2012 8:32:35 PM UTC-7, Massimo Di Pierro wrote:
>
> This is an excellent point.
>
> The closest we came to what you asked is the crud object. If a page 
> contains a single crud form and if the page is called with the json 
> extension, it reads the form variable from ?json. This allows one to 
> interact with the Crud object (create,read, update, delete) using html and 
> or rest-like approach.
> I say rest-like because it is not really restful. This is because we do 
> not use PUT and DELETE for Crud.
>
> Anyway, we are considering deprecating Crud because nobody used it this 
> way.
>
> The problem is that html forms and rest services are very different. html 
> forms assume a state (for preventing crsf, for checking permissions, etc.) 
> while rest services are not supposed to. One html page (one url) can 
> contain more crud elements while a restful URL deals with only one service 
> at the time. Html pages do not use PUT and DELETE (unless doing ajax) while 
> rest services do. Usually information in html and rest services is filtered 
> differently.
>
> Therefore we have developed different APIs for forms (SQLFORM, FORM) and 
> rest (@request.restful()).
>
> The only way to build a uniform APIs would be to have html forms and pages 
> get all their data via Ajax restful calls. Yet many users do not 
> want functional parts of their web site depending on JavaScript.
>
> In my view there is no simple solution to this problem and it is easier to 
> actually implement html forms and rest services separately. If you have any 
> advice on how to built a better system, I would like to hear your ideas. It 
> could help make web2py better.
>
> massimo
>
>
>
>
>
>
>
> On Saturday, 28 July 2012 21:41:34 UTC-5, Matthew Wood wrote:
>>
>> A quick question about basic CRUD for both humans (basic HTML) and 
>> computers
>> (REST)
>>
>> I'm trying to pick a solid python framework for a project at work.  We 
>> have a
>> lot of situations where we need to expose datbase tables for data CRUD.
>>
>> I'm trying to pick between Flask and Web2py at this time, but I've got a
>> specific need that I'm not sure is solved by either framework.
>>
>> Obviously for human consumption, I'll be using some sort of form-library 
>> that
>> will read the table-schema auto-create the form for me.  (Built in with 
>> Web2py,
>> WTForms + SQL-Alchemy for Flask.)  For the REST interfaces, I'll use a 
>> similar
>> library (Built in with Web2py, flask-rest for flask).
>>
>> What I'd REALLY like, is to have both the REST interfaces and html-forms 
>> use as
>> much of a common code-path as possible.  It's really frustrating when 
>> things
>> like data-validation work differently between one's REST interfaces and 
>> one's
>> html forms.
>>
>> Thusfar, in my investigations with both frameworks, I've felt that both
>> mechanisms appear quite different, and/or I have to do a lot of manual 
>> parsing
>> of XML in the Post/Put REST case.
>>
>> HOWEVER...  I've really only spent a little time investigating either one.
>> It's extremely likely that I'm just completely missing the best way to 
>> solve
>> the issue I'm describing.
>>
>> Can anyone point me to an example that works the way I'm describing?
>>
>> Hopefully, I have asked my question well enough.  :-) I'm feeling horribly
>> inelequent right now.
>>
>

-- 



Reply via email to