why use http.route() method use type="json" in openerp -


above code website_mail module controller file email_designer.py file

class websiteemaildesigner(http.controller):

@http.route('/website_mail/email_designer/<model("email.template"):template>/', type='http', auth="user", website=true, multilang=true) def index(self, template, **kw):     values = {         'template': template,     }      return request.website.render("website_mail.designer_index", values)  @http.route(['/website_mail/snippets'], type='json', auth="user", website=true) def snippets(self):     return request.website._render('website_mail.email_designer_snippets') 

which situation using type="json" , type="http" , why..??

both of them communication between client , server. httprequest communicates trough known , post methods. means following:

  • the client send request encoded in url (get method) or in http body (post method)
  • the server returns object corresponding request. html page, png image, css file, javascript, xml encoded data or whatever.

jsonrequest implementation of protocol client/server communication - json-rpc 2.0. may want lo took here form more information. it's remote procedure call (rpc) protocol means allows client initiate execution of method on server passing arguments method. in response client gets data result of method invocation.

edit - more words decorators @openerpweb.jsonrequest , @openerpweb.httprequest

some methods decorated @openerpweb.jsonrequest decorator, other methods - @openerpweb.httprequest. means nothing else first group of methods available execution trough json rpc protocol , second group accessible trough pure http protocol.

now, difference? need both jsonrequest , httprequest? let simplify this: json more suitable executing methods on server , obtain results. http simpler , easier use when access resource on server.

let's 'decorate' examples clarity. take @ following method of web.controllers.main.export class:

@openerpweb.jsonrequest def formats(self, req):     """ returns valid export formats      :returns: each export format, pair of identifier , printable name     :rtype: [(str, str)]     """     ... 

this method accepts arguments , returns list (python list object) containing known export formats. called in programmatic way in python code on client side.

on other side 'http' methods - method css() of web.controllers.main.web class:

@openerpweb.httprequest def css(self, req, mods=none):     .... 

all method return css file client. it's simple action accessing image, html web page or whatever other resource on server. resource returning here nothing complicated python list in previous example. don't need special format encode additionally. don't need additional data encoding format json , remote procedure call protocol json rpc.

type="json":

it call jsonrpc argument http.route() here , there json data able pass via jsonrpc, accept json data object argument.

type="http":

as compred json, http pass http request arguments http.route() not json data. examples

@http.route('demo_html', type="http") // work pefrect when call url def some_html(self):     return "<h1>this test</h1>"  @http.route('demo_json', type="json") // not working when call url def some_json(self):     return {"sample_dictionary": "this sample json dictionary"} 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -