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 2 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
1 change: 1 addition & 0 deletions 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)_

### Specload

Expand Down
47 changes: 47 additions & 0 deletions src/tools/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,53 @@ 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, your have to start elektrad instance. You can do it in two ways:

- run manually

- `cd libelektra/src/tools/web`
- `cd elektrad`
- `npm install`
- `npm start` (replaces `kdb run-elektrad`)
Copy link
Contributor

Choose a reason for hiding this comment

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

What means "replaces" here? From source you use npm start, if installed kdb run-elektrad. It seems to be that this instructions duplicate the instructions above or web/elektrad?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I just copy pasted what is written in https://www.libelektra.org/tools/web in the section "Running from source".

It means, that all 4 commands:

  • cd libelektra/src/tools/web
  • cd elektrad
  • npm install
  • npm start

replace kdb run-elektrad

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I just copy pasted

Please don't do this.

https://www.libelektra.org/tools/web is generated from this document.


- by installing elektrad tool together with Elektra and run it
- please see the documentation [here](https://www.libelektra.org/tools/web) on how to install and run the elektra-web tool
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this self-reference on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh sorry, I didn't notice that, I will improve this


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

As an example:

Let's create the new key-value pair `user/test`:

```sh
kdb set user/test 5
Copy link
Contributor

Choose a reason for hiding this comment

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

How to set via REST API?

```

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