Chris Miles wrote:

> Browsers already generate an Accept header indicating that they would  
> like HTML/XHTML.  For requests from scripts, get them to send an  
> appropriate Accept header for a format your application supports.  For  
> example, if they send "Accept: application/json" then your app can  
> respond with JSON.  

That's a terrific idea. Thanks.

> Your controller logic typically remains the same  
> accept for the response rendering (and then you can move that part to  
> a decorator to keep the controller methods clean).

I'm still not clear on how exactly I would do that (perhaps bc I'm only 
superficially familiar with either FormEncode or Formish validation, 
I'll probably will have to read more on that).

> Pylons (via WebOb) makes this easy by providing a request.accept  
> object representing the request Accept header.  So you can do, for  
> example:
>    request.accept.best_match("application/json")
> which will return True or False if the client will accept a JSON  
> response.
> See also http://pythonpaste.org/webob/reference.html#accept-headers
> 
>> But. The problem is complicated a bit by validation, which I would  
>> like
>> to keep the same for web UI and scripting API (I obviously don't  
>> want to
>> duplicate effort like producing separate code for web form value
>> validation and another portion of validation code values that come in
>> over scripting API).
> 
> If your validation code is independent of the response ..

Not quite, if I use Formish validation, or possibly, if I use FormEncode.

> then it can  
> remain the same, just render validation errors appropriately per  
> response type.

Decorator again?

Regards,
mk


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to