Re: [Cppcms-users] jsonrpc web service
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2012-01-12 09:26:17
|
Artyom Beilis -------------- CppCMS - C++ Web Framework: http://cppcms.sf.net/ CppDB - C++ SQL Connectivity: http://cppcms.sf.net/sql/cppdb/ ----- Original Message ----- > From: Leon <le...@wl...> > To: cpp...@li... > Cc: > Sent: Thursday, January 12, 2012 10:10 AM > Subject: [Cppcms-users] jsonrpc web service > > Hi, > > Thank you for the great framework! > > I have some questions regarding jsonrpc. > 1. How can I upload files using client side javascript (and how to > handle it on server side)? First of all there are plenty if examples http://art-blog.no-ip.info/cppcms_ref_v0_99/examples_page.html Including file upload http://art-blog.no-ip.info/cppcms_ref_v0_99/ex_uploads.html However, you should not upload files via JSON-RPC for several reasons: 1. JSON does not support binary format, only textual UTF-8 so in order to upload the file via JSON you'll have to encode it for example in base64 format and then decode it on server side. 2. It is much better to upload files via native POST interface and forms. > 2. The sample jsonrpc server functions all take built-in types as > parameters. Can structures or classes be used as parameters? Yes, two options: a) Use JSON value as is and as full json it can be a json object b) Define conversion from JSON to C++ object. See example http://art-blog.no-ip.info/cppcms_ref_v0_99/ex_json____json__cpp.html > 3. How can I generate api reference for my jsonrpc service? You mean simple method description (SMD)? Because it is not fully standardized it is not generated automatically. You can write your own SMD the way you want and set it using smd or smd_raw member functions of json_rpc_service: http://art-blog.no-ip.info/cppcms_ref_v0_99/classcppcms_1_1rpc_1_1json__rpc__server.html > 4. Is there any recommended way for authentication/security? > 1. CppCMS has session management that can be used for authentication. 2. For Ajax POST calls you may want to use CSRF tokens as well. There is a wide guide about it: http://art-blog.no-ip.info/wikipp/en/page/secure_programming > Thanks, > Lirong > Artyom |