Merge remote-tracking branch 'origin/master'
# Conflicts: # docs/source/examples/index.rst
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
Working with JSON
|
||||
==================
|
||||
|
||||
Nowadays webservices are json based so making your script json aware is probably
|
||||
a good chioce. In order to be able to extract data from and compose json
|
||||
documents from a script you can use
|
||||
`jq <https://https://stedolan.github.io/jq/>`_.
|
||||
|
||||
In this example we extract the name field from the incomming json document in
|
||||
order to generate a two attribute json response.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
who=$(kapow get /request/body | jq -r .name)
|
||||
kapow set /response/headers/Content-Type "application/json"
|
||||
kapow set /response/status 200
|
||||
jq --arg greet "Hello" --arg value "${who:-World}" -n \{greet:\$greet\,to:\$value\} | kapow set /response/body
|
||||
@@ -0,0 +1,20 @@
|
||||
Upload a file
|
||||
=============
|
||||
|
||||
HTTP request allows us to send and receive files by using the Multipart standard.
|
||||
|
||||
Kapow! allow us to handle files received in the request. In this example we
|
||||
respond back with the line count of the file received in the request.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
fname=$(kapow get /request/files/myfile/filename)
|
||||
lcount=$(kapow get /request/files/myfile/content | wc -l)
|
||||
kapow set /response/status 200
|
||||
echo "$fname has $lcount lines" | kapow set /response/body
|
||||
|
||||
You can try this by using the following curl:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
curl -F "myfile=@README.rst" http://localhost:8080/linecount
|
||||
Reference in New Issue
Block a user