对http动词的plone支持。
plone.rest的Python项目详细描述
扑通一声休息
目的
rest允许您使用http动词,如get、post、put、delete等。
rest代表代表状态转移。 创建松散耦合的web api是一种软件架构原则。
rest提供了基本的基础设施,允许我们在plone中构建restful端点。
将此基础结构与完整的plone rest api分离成一个单独的包的原因是,您可以创建针对特定用例的可选端点。这些特定终结点中的一些已经在使用中。
观众
rest面向有经验的web开发人员,他们希望在plone之上构建自己的http/rest端点。
如果您想使用现成的完整restful plone api,您应该使用plone.restapi。 该软件包使用并依赖于此软件包。
功能
-
为以下http动词注册restful服务端点:
- 发布
- 删除
- 补丁
- 选项
放 - 支持灵活和基于原型的内容对象
- 内容协商:可以为任意媒体类型(例如"application/json")注册服务。
- 命名服务允许为自定义URL注册服务终结点
注册restful服务端点
rest允许您使用zcml注册用于plone内容的http动词。
这就是如何在灵巧内容上注册修补程序请求:
<plone:servicemethod="PATCH"accept="application/json"for="plone.dexterity.interfaces.IDexterityContent"factory=".service.Patch"permission="cmf.ModifyPortalContent"/>
必须指定http动词(get、post、put、delete、head、options)。 用于内容协商的媒体类型,t内容对象的接口, 实际返回所需内容和权限的工厂类 访问服务。
工厂类需要从plone.rest'service'类继承,并实现返回响应主体的呈现方法:
from plone.rest import Service class Patch(Service): def render(self): return '{"message": "PATCH: Hello World!"}'
内容协商
要访问我们刚刚创建的服务端点,我们必须通过将"accept"头设置为"application/json"向灵巧对象发送get请求:
PATCH /Plone/doc1 HTTP/1.1 Host: localhost:8080 Accept: application/json
然后服务器将以"200 OK"响应:
HTTP/1.1 200 OK Content-Type: application/json { "message": "PATCH: Hello World!" }
您可以在命令行中尝试此操作:
$ http --auth admin:admin PATCH localhost:8080/Plone/doc1 Accept:application/json
< div >
注
您必须安装httpie(pip install httpie)才能使此示例起作用。
下面是所有支持的http动词的示例列表:
<:< /P>$ http --auth admin:admin GET localhost:8080/Plone/doc1 Accept:application/json
POST:
$ http --auth admin:admin POST localhost:8080/Plone/doc1 Accept:application/json
:
$ http --auth admin:admin PUT localhost:8080/Plone/doc1 Accept:application/json
删除:
$ http --auth admin:admin DELETE localhost:8080/Plone/doc1 Accept:application/json
修补程序:
<plone:servicemethod="PATCH"accept="application/json"for="plone.dexterity.interfaces.IDexterityContent"factory=".service.Patch"permission="cmf.ModifyPortalContent"/>0
选项:
<plone:servicemethod="PATCH"accept="application/json"for="plone.dexterity.interfaces.IDexterityContent"factory=".service.Patch"permission="cmf.ModifyPortalContent"/>1