Commit ef264f2a authored by Henri Cazottes's avatar Henri Cazottes
Browse files

doc(Readme): Add signed request example

parent 8ead09c2a845
......@@ -34,6 +34,9 @@ A RqlClient relies on an HttpClient. Two implementations are available
[CwSimpleHttpClient](src/client.ts#L332) and
[CwSigningHttpClient](src/client.ts#L462).
### CwSimpleHttpClient: anonymous request
[CwSimpleHttpClient](src/client.ts#L332) requires a baseUrl (the base url of a
cubicweb instance). A boolean can be added to allow cross origin requests. The
CwSimpleHttpClient can perform a doLogin(login,password) operation on the
......@@ -42,11 +45,6 @@ issues](#known-issues)). It can also be transformed into a CwSigningHttpClient
(toSigningClient()) after a doLogin() operation. It requires that the CubicWeb
user has at least an enabled token linked to his/her account.
[CwSigningHttpClient](src/client.ts#L462) requires a baseUrl (the base url of a
cubicweb instance), a tokenName, a tokenValue and a hashMethod code. Each
request will contain a Authorization header with the connection token and its
hashed value.
```javascript
import {providers, client} from '@logilab/cwclientlibjs';
......@@ -80,6 +78,33 @@ rqlClient.transactionV2([query]).then(res => {
});
```
### CwSigningHttpClient: authenticated requests.
[CwSigningHttpClient](src/client.ts#L462) requires a baseUrl (the base url of a
cubicweb instance), a tokenName, a tokenValue and a hashMethod code. Each
request will contain an Authorization header with the connection token and its
hashed value.
These tokens are managed on your CubicWeb instance under Profile > Actions > Add
> Authentication Token.
```javascript
import {providers, client} from '@logilab/cwclientlibjs';
// url is the base url of your cubicweb instance
const url = 'http://my-cubicweb-instance-base-url/';
const rqlClient = new client.CwRqlClient(
new client.CwSimpleHttpClient(url, "my-token-name", "1a2b3c4d5e6f...")
);
const query = 'Any X, Y WHERE X is BlogEntry, X entry_of Y';
rqlClient.queryRows(query).then(res => {
console.log(res); // [[123,1], [234, 2]]
});
```
## Providers.ts
The [provider](src/providers.ts) namespace provides two main objects:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment