Include simple example of usage in README.
* README.md
This commit is contained in:
parent
8d5d16a12e
commit
c0fe40ee4f
1 changed files with 78 additions and 1 deletions
79
README.md
79
README.md
|
|
@ -19,6 +19,82 @@ been brought up to our expectations of full production-quality code yet
|
||||||
still regard it as beta-quality software.
|
still regard it as beta-quality software.
|
||||||
|
|
||||||
|
|
||||||
|
## Simplest example
|
||||||
|
|
||||||
|
The following is provided as the simplest code to demonstrate use of the
|
||||||
|
dmbcs-micro-server library, not to inform of any coding style or quality
|
||||||
|
system approach. We assume a standard GNU system with recent
|
||||||
|
`make`, `bash`, `gcc`, etc.
|
||||||
|
|
||||||
|
Start with the HTML file `calc.html`
|
||||||
|
|
||||||
|
```html
|
||||||
|
<html>
|
||||||
|
<head><title>Multiplier</title></head>
|
||||||
|
<body><h1>Multiplier</h1>
|
||||||
|
<form action="compute" method="GET" id="calc">
|
||||||
|
<input type="text" name="arg_1"/> x <input type="text" name="arg_2"/>
|
||||||
|
= <input type="text" id="result" value="[result/]"></input>
|
||||||
|
<br>
|
||||||
|
<input type="submit">CALCULATE</input>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
```
|
||||||
|
|
||||||
|
And the C++ source file `calc.cc`
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#include <dmbcs-micro-server.h>
|
||||||
|
|
||||||
|
using namespace DMBCS::Micro_Server;
|
||||||
|
|
||||||
|
|
||||||
|
/* This function both serves up the basic HTML page, and
|
||||||
|
* performs the multiplication and injects the result into the
|
||||||
|
* HTML. */
|
||||||
|
void home_page (Query_String const &query, int const socket)
|
||||||
|
{
|
||||||
|
Hyper_Tags tags;
|
||||||
|
|
||||||
|
tags.add ("result",
|
||||||
|
query.get ("arg_1", 0) * query.get ("arg_2", 0));
|
||||||
|
|
||||||
|
Http_Server::return_html (socket,
|
||||||
|
substitute (tags,
|
||||||
|
slurp_file ("calc.html")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
auto server = Http_Server {2022,
|
||||||
|
{ {"", home_page},
|
||||||
|
{"compute", home_page} }};
|
||||||
|
|
||||||
|
for (;;) tick (server, 1000000);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
then the `makefile`
|
||||||
|
|
||||||
|
CXXFLAGS = `pkg-config --cflags dmbcs-micro-server`
|
||||||
|
LDFLAGS = `pkg-config --libs dmbcs-micro-server`
|
||||||
|
|
||||||
|
Then at the command line type
|
||||||
|
|
||||||
|
make calc
|
||||||
|
./calc
|
||||||
|
|
||||||
|
then point a browser at `http://localhost:2022/` and use the simple
|
||||||
|
calculator (donʼt try to do anything funny: the code has been kept
|
||||||
|
deliberately simple and doesnʼt do any error checking). Note that an
|
||||||
|
answer can be obtained directly with a URL like
|
||||||
|
`http://localhost:2022/compute?arg_1=3&arg_2=4`.
|
||||||
|
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
The *dmbcs-micro-server* source code is managed with *GIT* (configured
|
The *dmbcs-micro-server* source code is managed with *GIT* (configured
|
||||||
|
|
@ -61,4 +137,5 @@ If you use this application please consider a bitcoin donation if you
|
||||||
can. A small amount informs us that there is interest and that we are
|
can. A small amount informs us that there is interest and that we are
|
||||||
providing a useful service to the community; it will keep us motivated to
|
providing a useful service to the community; it will keep us motivated to
|
||||||
continue to make open source software. Donations can be made by bitcoin to
|
continue to make open source software. Donations can be made by bitcoin to
|
||||||
the address 1PWHez4zT2xt6PoyuAwKPJsgRznAKwTtF9, or by Ethereum to 0xd306277ef68026a64bdd8c99ac7f19f21b3da6fb.
|
the address 1PWHez4zT2xt6PoyuAwKPJsgRznAKwTtF9, or by Ethereum to
|
||||||
|
0xd306277ef68026a64bdd8c99ac7f19f21b3da6fb.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue