当前位置: 首页 > 工具软件 > Zotonic > 使用案例 >

zotonic api

连德义
2023-12-01

小例子

费了好力气才有所了解

在service下创建这样一个module----service_langxw_lxw (注意“没有serivice目录就创建这样一个目录)

个人很不理解为什么要一个api对应这样一个module,这样module会膨胀的很大

官方文档:http://zotonic.com/documentation/911/resource-api 看了好久也没全明白

 

 20 -module(service_langxw_lxw).

 21 -author("Arjan Scherpenisse <arjan@scherpenisse.net>").

 22 

 23 -svc_title("Retrieve a full export of an object.").

 24 -svc_needauth(false).


 26 -export([process_get/2, process_post/2]).

 27                           

 28 -include_lib("zotonic.hrl").

 29                           

 30 

 31 process_post(_ReqData, Context) ->

 32     ?DEBUG(_ReqData),

 33     ?DEBUG(Context),

 34     ?DEBUG({"z_context:get_q(id, Context)", z_context:get_q("id", Context)}),

 35 

 36     try 

 37         z:m()

 38     catch

 39         _:_ ->

 40             undefined

 41     end,

 42     %"OK".

 43      mochijson:encode("sdf").

 44 

 45 

 46 process_get(_ReqData, Context) ->

 47     ?DEBUG(_ReqData),

 48     ?DEBUG(Context),

 49     ?DEBUG({"z_context:get_q(id, Context)", z_context:get_q("id", Context)}),

 50 

 51     try 

 52         z:m()

 53     catch

 54         _:_ ->

 55             undefined                                                                                                                             

 56     end,

 57     %"OK".

 58      mochijson:encode("sdf").

 59     %case z_context:get_q("id", Context) of

 60     %    undefined ->


看到目录是service 想到-module(z_service). 打开发现一下内容,来post这样处理
146 %% define the handler mapping for the module.
147 handler('POST') ->
148     {process_post, 2};    
149 handler('GET') -> 
150     {process_get, 2};
151 handler('HEAD') ->
152     {process_get, 2};
153 handler('PUT') ->
154     {process_post, 2};
155 handler('DELETE') ->                                                                                                                              
156     {process_post, 2}.
157 

 类似资料:

相关阅读

相关文章

相关问答