Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Documentation/rest api web #2770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/news/_preparation_next_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)_
dmoisej marked this conversation as resolved.
Show resolved Hide resolved

### Specload

Expand Down Expand Up @@ -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)_
dmoisej marked this conversation as resolved.
Show resolved Hide resolved
- 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)_
- <<TODO>>

Expand Down
61 changes: 61 additions & 0 deletions src/tools/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
dmoisej marked this conversation as resolved.
Show resolved Hide resolved

In order to test API on localhost, you have to start elektrad instance. You can do it in two ways:
dmoisej marked this conversation as resolved.
Show resolved Hide resolved

- run manually (if you would like to start it manually or you don't have eletrad-web tool installed)
dmoisej marked this conversation as resolved.
Show resolved Hide resolved

- `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`
dmoisej marked this conversation as resolved.
Show resolved Hide resolved

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.
dmoisej marked this conversation as resolved.
Show resolved Hide resolved

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:
dmoisej marked this conversation as resolved.
Show resolved Hide resolved

- 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"`.
dmoisej marked this conversation as resolved.
Show resolved Hide resolved

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

<!-- prettier-ignore-start -->

```json
{
"exists": true,
"name": "test",
"path": "user/test",
"ls": [
"user/test"
],
"value": "5",
"meta": ""
}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refer to the API docu for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will improve

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet done?

Copy link
Contributor Author

@dmoisej dmoisej Jun 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markus2330 it is done. In the file I showed, how the user can set a value via curl


<!-- prettier-ignore-end -->

## Auth

Currently, webd does not support authentication. The best way to work around
Expand Down