$ git clone https://github.com/hguo/mini-cxx-http-example
$ cd mini-cxx-http-example
$ cd build
$ cmake -DBOOST_ROOT=${your_boost_installation} -DCMAKE_INSTALL_PREFIX=${prefix}
$ make && make install
The header, library, and executable will be installed to ${prefix}
.
- Create a file /tmp/test, and add arbitrary contents, e.g.
This is a test.
- Run the example
$ cd ${prefix}
$ ./bin/test_zserver 9091
where 9091 is the port number.
- Open a web browser and visit http://localhost:9091/get?key, you will see the contents in /tmp/test.
Please read main.c for more details.
The API is in zserver.h.
Call zserver_start(int port)
to start a http server that binds the port. The function will return immediately after creating a thread that runs the http server.
Call zserver_stop()
to stop the http server.
Call zserver_commit_file(const char *key, const char *filename)
to add a filename into the key-value store.
You can retrieve the content of the file using the url http://your_server_address:port/get?your_key_name