mormot2路由
unit mvc.Controller.Api; interface uses system.SysUtils, system.StrUtils, system.Classes, mormot.core.base, mormot.core.os, mormot.core.rtti, mormot.core.log, mormot.core.text, mormot.net.sock, mormot.net.http, mormot.net.server, mormot.net.async, mormot.core.datetime, system.Rtti, system.NetEncoding; type TAPIController = record function SayHello(c: THttpServerRequestAbstract): cardinal; function Default(c: THttpServerRequestAbstract): cardinal; function MD5(c: THttpServerRequestAbstract): Cardinal; function Base64Encode(c: THttpServerRequestAbstract): Cardinal; function Base64Decode(c: THttpServerRequestAbstract): Cardinal; /// <summary> /// 在这里调用业务函数 /// </summary> function RunFunction(c: THttpServerRequestAbstract): Cardinal; /// <summary> /// 检查erp是否要更新 /// </summary> function CheckUpdaterERP(c: THttpServerRequestAbstract): Cardinal; /// <summary> /// 检查app是否要更新 /// </summary> function CheckUpdaterApp(c: THttpServerRequestAbstract): Cardinal; end; implementation uses mvc.SysObject, mvc.result, mvc.utils; { TAPIController } function TAPIController.Base64Decode(c: THttpServerRequestAbstract): Cardinal; begin var sText := UrlDecode(c.RouteValue['txt']); var s := mvc.utils.Base64Decode(sText); var v := TResult<string>.Create(HTTP_SUCCESS); v.data := s; c.SetOutJson(_JSON.Serialize(v)); Result := HTTP_SUCCESS; end; function TAPIController.Base64Encode(c: THttpServerRequestAbstract): Cardinal; begin var sText := UrlDecode(c.RouteValue['txt']); var s := mvc.utils.Base64Encode(sText); var v := TResult<string>.Create(HTTP_SUCCESS); v.data := s; c.SetOutJson(_JSON.Serialize(v)); Result := HTTP_SUCCESS; end; function TAPIController.CheckUpdaterApp(c: THttpServerRequestAbstract): Cardinal; begin end; /// <summary> /// 检查erp是否要更新, /api/checkupdate/erp /// </summary> function TAPIController.CheckUpdaterERP(c: THttpServerRequestAbstract): Cardinal; begin Result := HTTP_SUCCESS; end; function TAPIController.Default(c: THttpServerRequestAbstract): cardinal; begin c.OutContent := '缺省处理函数.%s' + NowToString; c.OutContentType := mine.text; Result := HTTP_SUCCESS; end; /// <summary> /// /api/md5/<txt> /// </summary> function TAPIController.MD5(c: THttpServerRequestAbstract): Cardinal; begin var sText := UrlDecode(c.RouteValue['txt']); var v := TResult<string>.Create(HTTP_SUCCESS); v.data := mvc.utils.MD5(sText); c.SetOutJson(_JSON.Serialize(v)); Result := HTTP_SUCCESS; end; /// <summary> /// /api/fun/IntToStr/<int:qty> /// </summary> function TAPIController.RunFunction(c: THttpServerRequestAbstract): Cardinal; begin Result := HTTP_SUCCESS; end; /// <summary> /// /api/say/<msg> /// </summary> function TAPIController.SayHello(c: THttpServerRequestAbstract): cardinal; begin var v := TResult<string>.Create(HTTP_SUCCESS); v.data := UrlDecode(c.RouteValue['msg']); c.SetOutJson(_JSON.Serialize(v)); Result := HTTP_SUCCESS; end; initialization var _ : TAPIController; _Router.Get('/api/say/<msg>', _.SayHello); _Router.Get('/api/md5/<txt>', _.MD5); _Router.Get('/api/base64/encode/<txt>', _.Base64Encode); _Router.Get('/api/base64/decode/<txt>', _.Base64Decode); _Router.Get('/api/fun/IntToStr/<int:qty>', _.RunFunction); _Router.Get('/api/checkupdate/erp', _.CheckUpdaterERP); end.
标签:function,HTTP,SUCCESS,TAPIController,Cardinal,mormot2,THttpServerRequestAbstract From: https://www.cnblogs.com/hnxxcxg/p/18307972