Skip to content

Commit c0e4069

Browse files
authored
Merge pull request #116 from Hrittik20/http-post
Add HTTP POST support and Create content docs example
2 parents b7884f3 + 3f26aec commit c0e4069

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

docs/custom.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,22 @@ The following example updates the content at the specified location.
9393
{
9494
"title": "My New Document Title"
9595
}
96+
97+
98+
Create content
99+
==============
100+
101+
The following example creates content at the specified path with the given JSON body.
102+
103+
.. http:example:: curl plone-client
104+
105+
POST /Plone/folder HTTP/1.1
106+
Host: localhost:8080
107+
Content-Type: application/json
108+
Accept: application/json
109+
Authorization: Basic YWRtaW46YWRtaW4=
110+
111+
{
112+
"@type": "Document",
113+
"title": "My New Document"
114+
}

docs/plone_client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ def patch_content(request: HTTPRequest):
6868
cli.updateContent({python_to_js_literal(payload)});
6969
"""
7070

71+
def post_content(request: HTTPRequest):
72+
url = urlparse(request.url())
73+
path = f'/{url.path.split("/", 2)[-1]}'
74+
payload = {
75+
"path": path,
76+
"data": request.data(),
77+
}
78+
return f"""\
79+
cli.createContent({python_to_js_literal(payload)});
80+
"""
81+
7182

7283
def build_plone_client_command(request: HTTPRequest):
7384
url = urlparse(request.url())
@@ -89,4 +100,6 @@ def build_plone_client_command(request: HTTPRequest):
89100
return output + get_content(request)
90101
elif request.command == "PATCH":
91102
return output + patch_content(request)
103+
elif request.command == "POST":
104+
return output + post_content(request)
92105
return output

0 commit comments

Comments
 (0)