delphi - Delphi XE2 pro 中的 REST 服务器

标签 delphi rest delphi-xe2

我在 Delphi 7 的应用程序中嵌入了一个(非常简单)自制的 REST 服务器(带有 ICS + 一些东西),它可以工作,但不容易维护和扩展。 现在我使用 Delphi XE2 Pro(没有 DataSnap),我会改用更标准的解决方案,但又很简单。

有一个很好的简单方法吗?

最佳答案

Habari Web Components框架是一个简单的(商业)HTTP 服务器框架,适用于 Delphi 2009 及更高版本。随着TdjRestfulComponent它还包括 REST 扩展。 (我是这些库的开发者)

TdjRestfulComponent 配置可以以类似属性/注释的样式或更传统的过程样式方式完成。

所有 HTTP 方法和内容类型都可以映射到不同的匿名方法,并且仍然共享相同的资源 URI(一个 URI,不同的资源表示 - 取决于请求的内容类型)。例如,要以 HTML、XML 或 JSON 表示资源 /myresource,可以这样配置:

// 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);

该组件还支持路径参数:

&Path('orders/{orderId}/lines/{lineNo');

将解析如下 URL

http://mydomain.local:8080/context/orders/65432/lines/1

进入其他查询参数(orderId=65431lineNo=1)

关于delphi - Delphi XE2 pro 中的 REST 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10535257/

相关文章:

web-services - RESTful URL 设计 : public vs private API, 层次结构 API 设计模式,URI 与 URL 设计?

delphi - 修剪文件名但保留文件扩展名

delphi - 如何更改默认的delphi停靠窗体标题高度?

delphi - 如何在资源脚本的数据部分中使用宏?

Delphi:只需突出显示 SynEdit 中的文本

delphi - 有没有办法在不包含系统单元的情况下启用调试 DCU?

java - 两个 servlet 中的 Spring、MVC 和 REST

xml - 在 Delphi 中访问部分 XML 文档

java - 获取特定迭代下的所有任务(符合条件)?

multithreading - 如何避免TForm.Caption中的 “(not responding)”?