phi*_*ext 7 delphi rest delphi-xe2
我在Delphi 7的应用程序中嵌入了一个(非常简单的)自制REST服务器(带有ICS +一些stuf),它可以工作但不易维护和扩展.现在我使用Delphi XE2 Pro(没有DataSnap),我会改变更标准的解决方案,但又简单.
这样做容易吗?
在Habari的Web组件框架是2009年和较新的德尔福简单的(商业)HTTP服务器框架.使用TdjRestfulComponent,它还包含REST扩展.(我是这些库的开发者)
TdjRestfulComponent配置可以以类似属性/注释的样式或以更传统的过程样式方式完成.
所有HTTP方法和内容类型都可以映射到不同的匿名方法,并且仍然共享相同的资源URI(一个URI,不同的资源表示 - 取决于请求的内容类型).例如,要/myresource以HTML,XML或JSON 表示资源,可以像这样配置:
// respond to HTML browser GET request
&Path('myresource');
&Produces('text/html');
GET(procedure(Request: TRequest; Response: TResponse)
begin
Response.ContentText := '<html>Hello world!</html>';
end);
// respond to XML client
&Path('myresource');
&Produces('application/xml');
GET(procedure(Request: TRequest; Response: TResponse)
begin
Response.ContentText := '<xml>Hello world!</xml>';
end);
// respond to JSON client
&Path('myresource');
&Produces('application/json');
GET(procedure(Request: TRequest; Response: TResponse)
begin
Response.ContentText := '{"msg":"Hello world!"}';
end);
Run Code Online (Sandbox Code Playgroud)
该组件还支持路径参数:
&Path('orders/{orderId}/lines/{lineNo');
Run Code Online (Sandbox Code Playgroud)
将解析像这样的URL
http://mydomain.local:8080/context/orders/65432/lines/1
Run Code Online (Sandbox Code Playgroud)
到其他查询参数(orderId=65431和lineNo=1)