-
Log in to Alfresco Share:
- Open a web browser and enter the URL: http://localhost:8080/share
- If prompted, log in with the user name admin and password admin.
- Navigate to Data Dictionary > Web Scripts Extensions > org > example.
-
Create a web script description document for your request body sample:
- In the Create menu, select XML.
- Enter the name for the web script in the Name field: requestbody.post.desc.xml
-
Type the following in the content box:
<webscript> <shortname>Request Body Sample</shortname> <description>Render the request body in the response</description> <url>/requestbody</url> <authentication>user</authentication> </webscript>
- Click Create.
- Navigate back to the org/example folder using the breadcrumb trail.
-
Create a controller script for your request body sample:
- In the Create menu, select Plain Text.
- Enter the name in the Name field: requestbody.post.js
-
Type the following in the content box:
model.requestcontent = requestbody.content;
- Click Create.
- Navigate back to the org/example folder using the breadcrumb trail.
-
Create an HTML response template for your request body sample:
- In the Create menu, select Plain Text.
- Enter the name in the Name field: requestbody.post.html.ftl
-
Type the following in the content box:
${requestcontent}
- Click Create.
- Navigate back to the org/example folder using the breadcrumb trail.
-
Register the web scripts with Alfresco Community Edition.
- In a new web browser tab, enter the URL: http://localhost:8080/alfresco/service/index
- If prompted, log in with the user name admin and password admin.
- Click Refresh Web Scripts.
A message indicates there is an additional web script.
Your example consists of just two lines of code. The controller script extracts the request content from the requestbody root object and places it into the Web script model under the name requestcontent. The response template simply outputs the model value into the response.
-
Test this web script with cURL by typing the following in your command line:
curl -uadmin:admin -H "Content-Type: application/json" --data-binary "{\"request\":\"body\"}" "http://localhost:8080/alfresco/service/requestbody"
This posts a request body of {"request": "body"} to your web script, which in turn responds with: {"request": "body"}
