diff --git a/doc/news/_preparation_next_release.md b/doc/news/_preparation_next_release.md index 71e6a440511..7d2c2a8d199 100644 --- a/doc/news/_preparation_next_release.md +++ b/doc/news/_preparation_next_release.md @@ -321,6 +321,7 @@ The following section lists news about the [modules](https://www.libelektra.org/ ### Reference - Fixed missing Metadata in README and METADATA.ini. _(Michael Zronek)_ +- Update README.md web tool to show, how to test REST API on localhost. _(Dmytro Moiseiuk)_ ### Specload @@ -445,7 +446,7 @@ you up to date with the multi-language support provided by Elektra. - JNA is now not experimental anymore. _(Markus Raab)_ - gsettings is not default anymore. _(Markus Raab)_ -- Add fix for creating the Key and KeySet objects in the HelloElektra.java file _(Dmytro Moiseiuk)_ +- Add fix for creating the Key and KeySet objects in the HelloElektra.java file. _(Dmytro Moiseiuk)_ - We fixed a [warning about a deprecated default constructor](https://issues.libelektra.org/2670) in the C++ binding reported by GCC 9.0. _(René Schwaiger)_ - <> diff --git a/src/tools/web/README.md b/src/tools/web/README.md index 71154ed38e7..945a4418d01 100644 --- a/src/tools/web/README.md +++ b/src/tools/web/README.md @@ -114,6 +114,67 @@ Elektra web consists of multiple components: - [elektrad](https://master.libelektra.org/doc/api_blueprints/elektrad.apib), documentation: https://elektrad.docs.apiary.io/ - [webd](https://master.libelektra.org/doc/api_blueprints/webd.apib), documentation: https://elektrawebd.docs.apiary.io/ +## Test REST API on localhost + +In order to test API on localhost, you have to start elektrad instance. You can do it in two ways: + +- run manually (if you would like to start it manually or you don't have eletrad-web tool installed) + + - `cd libelektra/src/tools/web` + - `cd elektrad` + - `npm install` + - `npm start` + +- by installing elektrad tool together with Elektra and run it + - please see the section `Building with elektra-web Tool` + +Now the server is runing on [http://localhost:33333](http://localhost:33333). After that you can test API with help of Postman or other tool, which allows to send REST API requests. + +Additional note. It is recommended to install the elektrad tool than starting the server manually. +When Elektra is installed, the `kdb` command together with its tools is installed globally. +For instance, whenever you would like to write any shell script, which has to start a REST API server, you can just add the following line `kdb run-elektrad` inside your file and save it. +After that, the created shell script can be executed from any directory. + +Examples: + +let's create the new key-value pair `user/test` and set its value to 5. You can do it next way: + +- through the command terminal + ```sh + kdb set user/test 5 + ``` +- through the rest api using curl + ```sh + curl -X PUT -H "Content-Type: text/plain" --data "5" http://localhost:33333/kdb/user/test + ``` + +The output of any of two commands will be: `Set string to "5"`. If the specified key didn't exist before, then the output will be `Create a new key user/test with string "5"`. + +Now, the command + +```sh +curl http://localhost:33333/kdb/user/test +``` + +will return us the value of the specified key `user/test`, which is stored in the database right now + + + +```json +{ + "exists": true, + "name": "test", + "path": "user/test", + "ls": [ + "user/test" + ], + "value": "5", + "meta": "" +} +``` + + + ## Auth Currently, webd does not support authentication. The best way to work around