Skip to content

Commit

Permalink
document new builder step
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Weirich <matthias.weirich@selectcode.de>
  • Loading branch information
vavido committed Jan 4, 2021
1 parent 25d5b75 commit da2ef9f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
22 changes: 12 additions & 10 deletions javascript/lib/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Basically it makes sense to trigger the build process once from
the [parent module](../../README.md). Then you'll be able to
use the default build process in here:

```
```shell
npm install
npm run build
npm run lint
Expand All @@ -36,20 +36,20 @@ the variable `client` to be an instance of `ThingsClient` for the following usag
explanations.

The client provides different handles to handle requests for specific parts of the Things API:
```
```typescript
const thingsHandle = client.getThingsHandle();
```

The handles' methods will send requests and return their responses asynchronously.
For example the code to update a Thing would look like this:
```
```typescript
const thing = new Thing('the:thing');
thingsHandle.putThing(thing)
.then(result => console.log(`Finished putting thing with result: ${JSON.stringify(result)}`));
```

Additionally options for requests can be specified and passed on to the methods:
```
```typescript
const options = DefaultFieldsOptions.getInstance();
options.ifMatch('A Tag').withFields('thingId', 'policyId', '_modified');
thingsHandle.getThing('Testthing:TestId', options)
Expand All @@ -64,10 +64,12 @@ Each implementation will provide an HTTP implementation of the `ThingsClient` an
will use HTTP requests to communicate with Eclipse Ditto. The builder for the
client will guide you through the following steps.

```
```typescript
client = builder
// You can decide whether the client will use a TLS (https) connection or not:
.withTls() // or .withoutTls()
// Optional step if path to the api is not simply /api
//.withCustomPath('/custom/path/to/api')
// which domain the client will connect to
.withDomain('localhost:8080')
// Which auth provider to use. E.g. for basic auth there are different versions
Expand All @@ -84,7 +86,7 @@ Similar to the HTTP Client, each implementation will provide an WebSocket implem
of the `ThingsClient` that will use a WebSocket connection to communicate with
Eclipse Ditto. The builder for the client will guide you through the following steps.

```
```typescript
client = builder
// You can decide whether the client will use a TLS (https) connection or not:
.withTls() // or .withoutTls()
Expand All @@ -107,7 +109,7 @@ client = builder
### Errors
There are a few error responses that are not defined within the Eclipse Ditto API. These mainly relate to problems
with the web socket connection.
```
```json5
{
status: 0,
error: 'connection.unavailable',
Expand All @@ -117,7 +119,7 @@ with the web socket connection.
```
This error is returned when the buffer is turned off and the WebSocket connection is not currently established.
A connection is still being attempted.
```
```json5
{
status: 1,
error: 'connection.interrupted',
Expand All @@ -127,7 +129,7 @@ A connection is still being attempted.
```
This error is returned when the WebSocket connection failed while a request was waiting for it's response.
It's not possible to tell whether the request was received by the service or not.
```
```json5
{
status: 2,
error: 'connection.lost',
Expand All @@ -137,7 +139,7 @@ It's not possible to tell whether the request was received by the service or not
```
This error is returned when the connection to the service could not be established/reestablished.
Any future requests will return the same error.
```
```json5
{
status: 3,
error: 'buffer.overflow',
Expand Down
7 changes: 4 additions & 3 deletions javascript/lib/dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Basically it makes sense to trigger the build process once from
the [parent module](../../README.md). Then you'll be able to
use the default build process in here:

```
```shell
npm install
npm run build
npm run lint
Expand All @@ -25,14 +25,14 @@ npm test

## Using

```
```shell
# replace <ditto-major.minor> with the major and minor version number of Eclipse Ditto you are using.
npm i --save @eclipse/ditto-javascript-client-api_<ditto-major.minor> @eclipse/ditto-javascript-client-dom_<ditto-major.minor>
```

Create an instance of a client:

```
```javascript
const domain = 'localhost:8080';
const username = 'ditto';
const password = 'ditto';
Expand All @@ -45,6 +45,7 @@ const client = DittoDomClient.newHttpClient()
.apiVersion2()
.build();
```
To use a path other than `/api` to connect to ditto, the optional step `.withCustomPath('/path/to/api')` can be used.

To find out how to use the client, have a look at the [api documentation](../api/README.md#Using-the-client),
since the API will stay the same no matter what implementation is used.
9 changes: 5 additions & 4 deletions javascript/lib/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Basically it makes sense to trigger the build process once from
the [parent module](../../README.md). Then you'll be able to
use the default build process in here:

```
```shell
npm install
npm run build
npm run lint
Expand All @@ -20,14 +20,14 @@ npm test

## Using

```
```shell
# replace <ditto-major.minor> with the major and minor version number of Eclipse Ditto you are using.
npm i --save @eclipse/ditto-javascript-client-api_<ditto-major.minor> @eclipse/ditto-javascript-client-node_<ditto-major.minor>
```

Create an instance of a client:

```
```javascript
const domain = 'localhost:8080';
const username = 'ditto';
const password = 'ditto';
Expand All @@ -40,6 +40,7 @@ const client = DittoNodeClient.newHttpClient()
.apiVersion2()
.build();
```
To use a path other than `/api` to connect to ditto, the optional step `.withCustomPath('/path/to/api')` can be used.

To find out how to use the client, have a look at the [api documentation](../api/README.md#Using-the-client),
since the API will stay the same no matter what implementation is used.
Expand All @@ -50,7 +51,7 @@ The Node.js implementation supports setting up a proxy.
Currently it supports either reading directly from 'https_proxy' (or 'HTTPS_PROXY') environment variable
or manually setting the proxy settings.

```
```javascript
// may also omit one or more of the options
const proxyOptions = {
url: 'PROXY-URL:PROXYPORT',
Expand Down

0 comments on commit da2ef9f

Please sign in to comment.