doc: tutorial style fixes

This commit is contained in:
pancho horrillo
2019-12-10 18:01:29 +01:00
parent 94b284f625
commit ae68cf8fed
6 changed files with 233 additions and 211 deletions
+17 -9
View File
@@ -3,23 +3,23 @@ Your First Day at Work
**Senior** **Senior**
Welcome to ACME Inc. This is your first day here, right? Welcome to *ACME Inc.* This is your first day here, right?
**Junior** **Junior**
Hi! I am excited to start working. What will be my first task? Hi! Yes! And I am eager to start working. What will be my first task?
**Senior** **Senior**
First let me explain to you what is our infrastructure. First, let me help you get acquainted with our infrastructure.
**Junior** **Junior**
Ok. OK.
**Senior** **Senior**
We have two Linux machines that provide services to our employees. We have two Linux boxen that provide services to our employees.
1. The Corporate Server: Provides email, database and web services. 1. The Corporate Server: Provides email, database and web services.
@@ -28,10 +28,18 @@ Your First Day at Work
**Junior** **Junior**
That's it? Ok, just like Google. That's it? OK, just like Google, then.
**Senior** **Senior**
Well, I think is time for you to start with your first task. It just Smartass...
so happens that we received another request to backup the database
from the projects team. **Junior**
(chuckles nervously).
**Senior**
Well, I think is time for you to start with your first task. It just so
happens that we received another request to backup the database from the
projects team.
+39 -37
View File
@@ -7,20 +7,22 @@ Backup that Database!
**Senior** **Senior**
Well, is not that simple. We of course have periodic backups. But, our Well, is not that simple. We of course have periodic backups. But, our
project team ask us for a backup every time a project is finished. project team ask us for a backup every time a project is finished.
I've already prepared a script to do the task. Before executing it in I've already prepared a script to do the task. Before executing it in
production download it and test it in your own machine. production download it and test it in your own machine.
.. code-block:: console .. code-block:: console
$ curl --output backup_db.sh 'https://raw.githubusercontent.com/BBVA/kapow/master/docs/source/tutorial/materials/backup_db.sh' $ curl --output backup_db.sh https://raw.githubusercontent.com/BBVA/kapow/master/docs/source/tutorial/materials/backup_db.sh
$ chmod u+x backup_db.sh $ chmod u+x backup_db.sh
**Junior** **Junior**
Ok, done! When I executed it the output says: (after a few minutes)
OK, done! When I executed it the output says:
.. code-block:: console .. code-block:: console
@@ -30,11 +32,11 @@ Backup that Database!
**Senior** **Senior**
That's right. That script performed the backup and stored it into the That's right. That script performed the backup and stored it into the
**Backup Server** and appended some information into the backup log **Backup Server** and appended some information into the backup log file at
file at ``/tmp/backup_db.log``. ``/tmp/backup_db.log``.
Now you can SSH into the **Corporate Server** and make the real Now you can ``ssh`` into the **Corporate Server** and make the real
backup. backup.
@@ -54,32 +56,33 @@ Backup that Database!
**Senior** **Senior**
I am the only allowed to SSH into the **Corporate Server** for obvious I am the only one allowed to ``ssh`` into the **Corporate Server**, for
reasons. obvious reasons.
**Junior** **Junior**
Why do you need to SSH in the first place? Couldn't it be done Why do you need to ``ssh`` in the first place? Couldn't it be done without
without SSH? ``ssh``?
**Senior** **Senior**
Actually it could be done with a promising new tool I've just found... Actually, it could be done with a promising new tool I've just found...
Kapow! *Kapow!*
Is a tool that allows you to publish scripts as HTTP services. If we Is a tool that allows you to publish scripts as ``HTTP`` services. If we
use it here we can give them the ability to do the backup whenever use it here we can give them the ability to do the backup whenever
they want. they want.
**Junior** **Junior**
Sounds like less work for me. I like it. Sounds like less work for me. I like it!
**Senior** **Senior**
Ok then, let's try on your laptop first. OK then, let's it try on your laptop first.
First of all you have to follow the `installation instructions </the_project/install_and_configure>`_. First of all, you have to follow the
`installation instructions </the_project/install_and_configure>`_.
**Junior** **Junior**
@@ -88,10 +91,10 @@ Backup that Database!
**Senior** **Senior**
Don't worry it is pretty easy. Basically we will provide an HTTP Don't worry, it is pretty easy. Basically we will provide an ``HTTP``
endpoint managed by *Kapow!* at the **Corporate Server**; when the endpoint managed by *Kapow!* at the **Corporate Server**; when the project
project team wants to perform a backup they only need to call the team wants to perform a backup they only need to call the endpoint and
endpoint and *Kapow!* will call the backup script. *Kapow!* will call the backup script.
**Junior** **Junior**
@@ -99,7 +102,7 @@ Backup that Database!
**Senior** **Senior**
First you have to start a fresh server. Please run this in your laptop: First you have to start a fresh server. Please run this in your laptop:
.. code-block:: console .. code-block:: console
@@ -107,8 +110,8 @@ Backup that Database!
.. warning:: .. warning::
It is important that you run this command in the same directory It is important that you run this command in the same directory in which
in which you downloaded ``backup_db.sh``. you downloaded ``backup_db.sh``.
**Junior** **Junior**
@@ -116,7 +119,7 @@ Backup that Database!
**Senior** **Senior**
Now you have the port 8080 open but don't have any endpoints defined. Now you have the port ``8080`` open but don't have any endpoints defined.
To define our endpoint you have to run this in another terminal: To define our endpoint you have to run this in another terminal:
.. code-block:: console .. code-block:: console
@@ -124,8 +127,8 @@ Backup that Database!
$ kapow route add -X PUT /db/backup -e ./backup_db.sh $ kapow route add -X PUT /db/backup -e ./backup_db.sh
This will create an endpoint accessible via This will create an endpoint accessible via
``http://localhost:8080/db/backup``. This endpoint have to be invoked ``http://localhost:8080/db/backup``. This endpoint has to be invoked with the
with the ``PUT`` method to prevent accidental calls. ``PUT`` method to prevent accidental calls.
**Junior** **Junior**
@@ -134,10 +137,9 @@ Backup that Database!
**Senior** **Senior**
Not at all. The have thought of everything. You can put all your route Not at all. The creators of *Kapow!* have thought of everything. You can put
definitions in a special script file and pass it to the server on all your route definitions in a special script file and pass it to the server
startup. They call those files `POW` files and have ``.pow`` on startup. They call those files `pow` files and they have ``.pow`` extension.
extension.
It should look something like: It should look something like:
@@ -167,7 +169,7 @@ Backup that Database!
**Senior** **Senior**
That appears to be the case, but better we check it. That appears to be the case, but we better check it.
Call it with ``curl``: Call it with ``curl``:
@@ -177,11 +179,11 @@ Backup that Database!
**Junior** **Junior**
Yay! I can see the log file at ``/tmp/backup_db.log`` Yay! I can see the log file at ``/tmp/backup_db.log``
**Senior** **Senior**
That's great. I am going to install all this in the *Corporate Server* That's great. I am going to install all this in the *Corporate Server* and
and forget about the old procedure. forget about the old procedure.
That enough for your first day! You can go home. That enough for your first day! Go home now and get some rest.
+16 -16
View File
@@ -1,44 +1,44 @@
What we've done? What have we done?
================ ==================
**Senior** **Senior**
Ey, I come from seeing our project team mates. They're delighted with their Ey, I come from seeing our project team mates. They're delighted with their
new toy, but they miss something. new toy, but they miss something.
I forgot to tell you that after the backup run they need to review the log I forgot to tell you that after the backup is run they need to review the log
file to check that all went ok. file to check that all went OK.
**Junior** **Junior**
Makes sense. Do you think that *Kapow!* can help with this? I feel that this is Makes sense. Do you think that *Kapow!* can help with this? I have the
the way to do it. feeling that this is the right way to do it...
**Senior** **Senior**
Sure! Let's take a look at the documentation to see how can we tweak with the Sure! Let's take a look at the documentation to see how we can tweak the
logic of the request. logic of the request.
**Junior** **Junior**
Got it! There're a Got it! There're a
`lot of resources to work with </theory/resource_tree.rst>`_, I see that we `lot of resources to work with </theory/resource_tree.rst>`_, I see that we
can write to the response, do you think this will work for us? can write to the response. Do you think this will work for us?
**Senior** **Senior**
Yeah, they used to cat the log file contents to see what happened in the Yeah, the team is used to ``cat`` the log file contents to see what happened
last execution: in the last execution:
.. code-block:: console .. code-block:: console
$ cat /tmp/backup_db.log $ cat /tmp/backup_db.log
I've make it easy for you, do you dare to do it? I've made it easy for you. Are you up to it?
**Junior** **Junior**
Let me try add this to our ``POW`` file: Let me try add this to our ``pow`` file:
.. code-block:: console .. code-block:: console
@@ -47,13 +47,13 @@ What we've done?
**Senior** **Senior**
Looks good to me, clean and simple, and it is a very good idea to use ``GET`` Looks good to me, clean and simple, and it is a very good idea to use ``GET``
here as it wont change anything in the server. Restart *Kapow!* and try it. here as it wont change anything in the server. Restart *Kapow!* and try it.
**Junior** **Junior**
Wooow! I get back the content of the file. If they liked the first one they're Wooow! I get back the content of the file. If they liked the first one
going to love this. they're going to loooove this.
**Senior** **Senior**
Agree. we've done the day with this... Agree. We are done for the day with this...
+25 -24
View File
@@ -3,43 +3,44 @@ We need to filter
**Senior** **Senior**
Hi guy! How're you doing this morning? I've got a new challenge from our Hiya! How're you doing this morning? I've got a new challenge from our
grateful mates. grateful mates.
As time goes on from the last rotation the size of the log file gets bigger. As time goes on from the last log rotation, the size of the log file gets
Furthermore, they want to limit the output of the file to pick only some bigger and bigger. Furthermore, they want to limit the output of the file to
records and only from the end of the file. We need to do something to help pick only some records, and only from the end of the file. We need to do
them as they waste a lot of time reviewing the output. something to help them as they are wasting a lot of time reviewing the output.
**Junior** **Junior**
My two cents is that this time is going to be more of a deep bash knowledge. I have a feeling that this is going to entail some serious *bash-foo*. What
Do you agree? do you think?
**Senior** **Senior**
By sure, but in addition to some good shell plumbing we're going to squeeze Sure! But in addition to some good shell plumbing we're going to squeeze
*Kapow!*'s superpowers a litle bit more to get a really good solution. *Kapow!*'s superpowers a litle bit more to get a really good solution.
Can you take a look at *Kapow!*'s documentation to see if something can be done? Can you take a look at *Kapow!*'s documentation to see if something can be
done?
**Junior** **Junior**
I've seen in the documentation and there is a way to get access to the data I've read in the documentation that there is a way to get access to the data
comming in the request. Do you think we can use this to let them choose how coming in the request. Do you think we can use this to let them choose how
to do the filtering? to do the filtering?
**Senior** **Senior**
Sounds great! How we have lived without *Kapow!* all this time? Sounds great! How have we lived without *Kapow!* all this time?
As they requested, we can offer them with a parameter to filter the registers As they requested, we can offer them a parameter to filter the registers
they want to pick and another parameter to limit the output size in lines. they want to pick, and another parameter to limit the output size in lines.
**Junior** **Junior**
Sounds that will be enough. Now we have to make some modifications to our Sounds about right. Now we have to make some modifications to our last
last endpoint definition to add this new feature. Let's start working... endpoint definition to add this new feature. Let's get cracking!
**Senior** **Senior**
@@ -51,20 +52,20 @@ We need to filter
| tail -n "$(kapow get /request/params/lines)" \ | tail -n "$(kapow get /request/params/lines)" \
| kapow set /response/body' | kapow set /response/body'
It looks a bit weird but we'll have time to re-styling later. Please make It looks a bit weird, but we'll have time to revise the style later. Please
some tests on your laptop before to publish on the *Corporate Server*. make some tests on your laptop before we publish it on the *Corporate Server*.
Remember to send them an example URL with the parameters the can use to Remember to send them an example URL with the parameters they can use to
filter. filter and limit the amount of lines they get.
**Junior** **Junior**
Ok, Should look like this, isn't it? OK, should look like this, doesn't it?
.. code-block:: console .. code-block:: console
$ curl http://localhost:8080/db/backup_logs?filter=rows%20inserted&lines=200 $ curl 'http://localhost:8080/db/backup_logs?filter=rows%20inserted&lines=200'
**Senior** **Senior**
Exactly. Another great day helping the company to advance. Let's go for a Exactly. Another great day helping the company advance. Let's go grab a
beer for celebrating! beer to celebrate!
+68 -59
View File
@@ -1,23 +1,22 @@
I Need My Report I Need my Report
================ ================
**Junior** **Junior**
Good morning! Good morning!
You look very busy, what's the matter? You look very busy, what's going on?
**Senior** **Senior**
I am finishing the capacity planning report. Let me just I am finishing the capacity planning report. Let me just mail it... Done!
mail it... Done!
Today I am going to teach you how to do this report so we can split Today I am going to teach you how to write this report so we can split the
the workload. workload.
**Junior** **Junior**
Oh. That sounds... fun. Ok, tell me about this report. Oh. That sounds... fun. OK, tell me about this report.
**Senior** **Senior**
@@ -30,37 +29,44 @@ I Need My Report
**Junior** **Junior**
I see this company scales just like Google. I see this company scales up just like Google...
**Senior**
Smartass...
**Junior**
(chuckles)
**Senior** **Senior**
We have a procedure: We have a procedure:
1. SSH into the machine. 1. ``ssh`` into the machine.
2. Execute the following commands copying its output for later fill in 2. Execute the following commands copying its output for later filling in the
the report: report:
- ``hostname`` and ``date``: To include in the report. - ``hostname`` and ``date``: To include in the report.
- ``free -m``: To know if we have to buy more RAM. - ``free -m``: To know if we have to buy more RAM.
- ``uptime``: To see the load of the system. - ``uptime``: To see the load of the system.
- ``df -h``: Just in case we need another hard disk. - ``df -h``: Just in case we need another hard disk drive.
3. Copy all this in a mail and send it to *Susan*, the operations 3. Copy all this in an email and send it to *Susan*, the operations manager.
manager.
**Junior** **Junior**
And why *Susan* don't enter the server herself to see all of this? And why *Susan* can't ``ssh`` into the server herself to see all of this?
**Senior** **Senior**
She doesn't have time for this. She is a manager, she is very busy! She doesn't have time for this. She is a manager, and she is very busy!
**Junior** **Junior**
Well, I guess we can make a *Kapow!* endpoint to let her see all this Well, I guess we can make a *Kapow!* endpoint to let her see all this
information from the browser. This way she doesn't need to waste any information from the browser. This way she doesn't need to waste any time
time asking us. asking us.
I started to write it already: I started to write it already:
@@ -70,10 +76,10 @@ I Need My Report
**Senior** **Senior**
That is preposterous! Not good enough!
First of all that code is not readable. And the output would be First of all, that code is not readable. And the output would be something
something like. like:
.. code-block:: text .. code-block:: text
@@ -89,7 +95,7 @@ I Need My Report
Which is also very difficult to read! Which is also very difficult to read!
What *Susan* is used to see is more like: What *Susan* is used to see is more like this:
.. code-block:: text .. code-block:: text
@@ -114,9 +120,9 @@ I Need My Report
**Senior** **Senior**
That fix the issue for *Susan* but make it worst for us. That fixes the issue for *Susan*, but makes it worse for us.
What about a HEREDOC to help us make the code more readable. What about a HEREDOC to help us make the code more readable?
**Junior** **Junior**
@@ -132,9 +138,9 @@ I Need My Report
.. code-block:: console .. code-block:: console
$ cat <<-'EOF' $ cat <<-'EOF'
you can put you can put
more than one line more than one line
here here
EOF EOF
The shell will put the data between the first ``EOF`` and the second The shell will put the data between the first ``EOF`` and the second
@@ -142,43 +148,44 @@ I Need My Report
**Junior** **Junior**
If I want to use this with *Kapow!* I have to make it read the script OK, I understand. That's cool, by the way.
from ``stdin``. To do this I know that I have to put a ``-`` at the
end. So, if I want to use this with *Kapow!*, I have to make it read the script
from ``stdin``. To do this I know that I have to put a ``-`` at the end.
Let me try: Let me try:
.. code-block:: bash .. code-block:: bash
kapow route add /capacityreport - <<-'EOF' kapow route add /capacityreport - <<-'EOF'
hostname | kapow set /response/body hostname | kapow set /response/body
echo ================================================================================ | kapow set /response/body echo ================================================================================ | kapow set /response/body
date | kapow set /response/body date | kapow set /response/body
echo ================================================================================ | kapow set /response/body echo ================================================================================ | kapow set /response/body
free -m | kapow set /response/body free -m | kapow set /response/body
echo ================================================================================ | kapow set /response/body echo ================================================================================ | kapow set /response/body
uptime | kapow set /response/body uptime | kapow set /response/body
echo ================================================================================ | kapow set /response/body echo ================================================================================ | kapow set /response/body
df -h | kapow set /response/body df -h | kapow set /response/body
echo ================================================================================ | kapow set /response/body echo ================================================================================ | kapow set /response/body
EOF EOF
**Senior** **Senior**
That would work. Nevertheless I am not satisfied. That would work. Nevertheless I am not yet satisfied.
What about all the repeated ``kapow set /response/body`` statements? What about all the repeated ``kapow set /response/body`` statements?
Could we do any better? Do you think we could do any better?
**Junior** **Junior**
Maybe we can redirect all to a file and use the file as the input of Maybe we can redirect all output to a file and use the file as the input of
``kapow set /response/body``. ``kapow set /response/body``.
**Senior** **Senior**
There is a better way. You can make use of another neat ``bash`` There is a better way. You can make use of another neat ``bash`` feature:
feature: **group commands**. **group commands**.
Group commands allows you to execute several commands treating the Group commands allows you to execute several commands treating the
group as one single command. group as one single command.
@@ -196,24 +203,26 @@ I Need My Report
.. code-block:: bash .. code-block:: bash
kapow route add /capacityreport - <<-'EOF' kapow route add /capacityreport - <<-'EOF'
{ {
hostname hostname
echo ================================================================================ echo ================================================================================
date date
echo ================================================================================ echo ================================================================================
free -m free -m
echo ================================================================================ echo ================================================================================
uptime uptime
echo ================================================================================ echo ================================================================================
df -h df -h
echo ================================================================================ echo ================================================================================
} | kapow set /response/body } | kapow set /response/body
EOF EOF
**Senior** **Senior**
I am not worried about maintaining that script. Good job! Nice! Now I am not worried about maintaining that script. Good job!
**Junior** **Junior**
You know me. Whatever it takes to avoid writing reports ;) You know me. Whatever it takes to avoid writing reports ;-)
(both chuckle).
+67 -65
View File
@@ -9,23 +9,23 @@ Sharing the Stats
Just about time... We are in trouble! Just about time... We are in trouble!
The report stuff was a complete success, so much that now *Susan* has The report stuff was a complete success, so much so that now *Susan* has hired
hired a frontend developer to create a custom dashboard to see the a frontend developer to create a custom dashboard to see the stats in real
stats in real time. time.
Now we have to provide the backend for the solution. Now we have to provide the backend for the solution.
**Junior** **Junior**
And whats the problem? And what's the problem?
**Senior** **Senior**
We are not developers what are we doing writing backend? We are not developers! What are we doing writing a backend?
**Junior** **Junior**
Chill out, man. Can't be that difficult? What they need exactly? Just chill out. Can't be that difficult... What do they need, exactly?
**Senior** **Senior**
@@ -34,20 +34,19 @@ Sharing the Stats
**Junior** **Junior**
So we have half of the work already done. So, we have half of the work done already!
What about this? What about this?
.. code-block:: bash .. code-block:: bash
kapow route add /capacitystats - <<-'EOF' kapow route add /capacitystats - <<-'EOF'
echo "{\"memory\": \"`free -m`\"}" | kapow set /response/body echo "{\"memory\": \"`free -m`\"}" | kapow set /response/body
EOF EOF
**Senior** **Senior**
For starters that's not valid JSON. The output would be something For starters, that's not valid ``JSON``. The output would be something like:
like:
.. code-block:: console .. code-block:: console
@@ -56,9 +55,8 @@ Sharing the Stats
Mem: 31967 3121 21680 980 7166 27418 Mem: 31967 3121 21680 980 7166 27418
Swap: 0 0 0"} Swap: 0 0 0"}
You can't add new lines inside a JSON string that way, you have to You can't add new lines inside a ``JSON`` string that way, you have to escape
encode with ``\n``. the new line characters as ``\n``.
**Junior** **Junior**
@@ -66,7 +64,7 @@ Sharing the Stats
**Senior** **Senior**
See it by yourself. See it for yourself.
.. code-block:: console .. code-block:: console
@@ -75,23 +73,23 @@ Sharing the Stats
**Junior** **Junior**
``jq``? What is that command? ``jq``? What is that command?
**Senior** **Senior**
``jq`` is a wonderful tool for working with JSON data from the command ``jq`` is a wonderful tool for working with ``JSON`` data from the command
line. With you ``jq`` you can extract data from JSON and also line. With ``jq`` you can extract data from a ``JSON`` document and it also
generate well-formed JSON. allows you to generate a well-formed ``JSON`` document.
**Junior** **Junior**
Let's use it then! Let's use it, then!
How can we generate a JSON document with ``jq``? How can we generate a ``JSON`` document with ``jq``?
**Senior** **Senior**
To generate a document we use the ``-n`` argument: To generate a document we use the ``-n`` option:
.. code-block:: console .. code-block:: console
@@ -102,11 +100,12 @@ Sharing the Stats
**Junior** **Junior**
That is not very useful. The output is the same. That does not seem very useful. The output is just the same.
**Senior** **Senior**
It get's better. You can add variables to the JSON and ``jq`` will escape them for you. Bear with me, it gets better. You can add variables to the ``JSON`` and
``jq`` will escape them for you.
.. code-block:: console .. code-block:: console
@@ -117,7 +116,9 @@ Sharing the Stats
**Junior** **Junior**
That's just what I need. Sweet! That's just what I need.
(hacks away for a few minutes).
What do you think of this? What do you think of this?
@@ -134,8 +135,8 @@ Sharing the Stats
**Senior** **Senior**
That is the data we have to produce. But the code is far from readable. And That is the output we have to produce, right. But the code is far from
you also forgot about adding the endpoint. readable. And you also forgot about adding the endpoint.
Can we do any better? Can we do any better?
@@ -146,60 +147,61 @@ Sharing the Stats
.. code-block:: bash .. code-block:: bash
kapow route add /capacitystats - <<-'EOF' kapow route add /capacitystats - <<-'EOF'
jq -n \ jq -n \
--arg hostname "$(hostname)" \ --arg hostname "$(hostname)" \
--arg date "$(date)" \ --arg date "$(date)" \
--arg memory "$(free -m)" \ --arg memory "$(free -m)" \
--arg load "$(uptime)" \ --arg load "$(uptime)" \
--arg disk "$(df -h)" \ --arg disk "$(df -h)" \
'{"hostname": $hostname, "date": $date, "memory": $memory, "load": $load, "disk": $disk}' \ '{"hostname": $hostname, "date": $date, "memory": $memory, "load": $load, "disk": $disk}' \
| kapow set /response/body | kapow set /response/body
EOF EOF
What do you think? What do you think?
**Senior** **Senior**
You forgot one more thing. I'm afraid you forgot an important detail.
**Junior** **Junior**
I think you are wrong, the JSON is well-formed and it contains all the I don't think so! the ``JSON`` is well-formed and it contains all the required
required data. Also the code is very readable. data. And the code is quite readable.
**Senior** **Senior**
You are right but, you are not using HTTP correctly. You have to set the You are right, but you are not using ``HTTP`` correctly. You have to set the
``Content-Type`` header to let your client know the format of the data you are ``Content-Type`` header to let your client know the format of the data you are
outputting. outputting.
**Junior** **Junior**
Ok, let me try: Oh, I see. Let me try again:
.. code-block:: bash .. code-block:: bash
kapow route add /capacitystats - <<-'EOF' kapow route add /capacitystats - <<-'EOF'
jq -n \ jq -n \
--arg hostname "$(hostname)" \ --arg hostname "$(hostname)" \
--arg date "$(date)" \ --arg date "$(date)" \
--arg memory "$(free -m)" \ --arg memory "$(free -m)" \
--arg load "$(uptime)" \ --arg load "$(uptime)" \
--arg disk "$(df -h)" \ --arg disk "$(df -h)" \
'{"hostname": $hostname, "date": $date, "memory": $memory, "load": $load, "disk": $disk}' \ '{"hostname": $hostname, "date": $date, "memory": $memory, "load": $load, "disk": $disk}' \
| kapow set /response/body | kapow set /response/body
echo application/json | kapow set /response/headers/Content-Type echo application/json | kapow set /response/headers/Content-Type
EOF EOF
**Senior** **Senior**
Just a couple of details. Better. Just a couple of details.
1. You have to set the headers **before** the body. This is because the body 1. You have to set the headers **before** writing to the body. This is
can be so big that *Kapow!* is forced to start sending it out. because the body can be so big that *Kapow!* is forced to start sending it
2. In cases where you want to set a small piece of data (like the header) is out.
better to not use the ``stdin``. *Kapow!* provides a secondary syntax for these 2. In cases where you want to set a small piece of data (like the header), it
cases: is better not to use ``stdin``. *Kapow!* provides a secondary syntax
for these cases:
.. code-block:: console .. code-block:: console
@@ -212,18 +214,18 @@ Sharing the Stats
.. code-block:: bash .. code-block:: bash
kapow route add /capacitystats - <<-'EOF' kapow route add /capacitystats - <<-'EOF'
kapow set /response/headers/Content-Type application/json kapow set /response/headers/Content-Type application/json
jq -n \ jq -n \
--arg hostname "$(hostname)" \ --arg hostname "$(hostname)" \
--arg date "$(date)" \ --arg date "$(date)" \
--arg memory "$(free -m)" \ --arg memory "$(free -m)" \
--arg load "$(uptime)" \ --arg load "$(uptime)" \
--arg disk "$(df -h)" \ --arg disk "$(df -h)" \
'{"hostname": $hostname, "date": $date, "memory": $memory, "load": $load, "disk": $disk}' \ '{"hostname": $hostname, "date": $date, "memory": $memory, "load": $load, "disk": $disk}' \
| kapow set /response/body | kapow set /response/body
EOF EOF
**Senior** **Senior**
That's perfect! Let's upload this to the *Corporate Server* and tell the That's perfect! Now, let's upload this to the *Corporate Server* and tell the
frontend developer. frontend developer about it.