Skip to content

Commit 321d855

Browse files
anweshangermanattanasio
authored andcommitted
feat(SDK): Add GDPR support (#680)
* Progress on request wrapper * Deleted extra file * feat(services): adds header option for each method and detailedResponse option * style(formatting): formatting changes * refactor(services): removes detailedResponse and adds test for getting header with third parameter * test(nlc credentials): update classifier id for failing nlc test * README update for request/response headers
1 parent b0b411c commit 321d855

File tree

18 files changed

+1641
-1062
lines changed

18 files changed

+1641
-1062
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Node.js client library to use the Watson APIs.
1414
* [Getting the Service Credentials](#getting-the-service-credentials)
1515
* [Usage](#usage)
1616
* [Client-side usage](#client-side-usage)
17+
* [Sending Request Headers](#sending-request-headers)
18+
* [Parsing HTTP Response](#parsing-http-response)
1719
* [Data collection opt-out](#data-collection-opt-out)
1820
* [Questions](#questions)
1921
* [Examples](#examples)
@@ -80,6 +82,54 @@ See the `examples/` folder for [Browserify](http://browserify.org/) and [Webpack
8082
Note: not all services currently support CORS, and therefore not all services can be used client-side.
8183
Of those that do, most require an auth token to be generated server-side via the [Authorization Service](#authorization).
8284

85+
### Sending Request Headers
86+
87+
Custom headers can be passed with any request. Each method has an optional parameter `headers` which can be used to pass in these custom headers, which can override headers that we use as parameters.
88+
89+
For example, this is how you can pass in custom headers to Watson Assistant service. In this example, the `'custom'` value for `'Accept-Language'` will override the default header for `'Accept-Language'`, and the `'Custom-Header'` while not overriding the default headers, will additionally be sent with the request.
90+
91+
```js
92+
var assistant = new watson.AssistantV1({
93+
/* username, password, version, url, etc... */
94+
});
95+
96+
assistant.message({
97+
workspace_id: 'something',
98+
input: {'text': 'Hello'},
99+
headers: {
100+
'Custom-Header': 'custom',
101+
'Accept-Language': 'custom'
102+
103+
}
104+
}, function(err, result, response) {
105+
if (err)
106+
console.log('error:', err);
107+
else
108+
console.log(JSON.stringify(result, null, 2));
109+
});
110+
111+
```
112+
113+
### Parsing HTTP Response
114+
115+
To retrieve the HTTP response, all methods can be called with a callback function with three parameters, with the third being the response. Users for example may retrieve the response headers with this usage pattern.
116+
117+
Here is an example of how to access the response headers for Watson Assistant:
118+
119+
```js
120+
var assistant = new watson.AssistantV1({
121+
/* username, password, version, url, etc... */
122+
});
123+
124+
assistant.message(params, function(err, result, response) {
125+
if (err)
126+
console.log('error:', err);
127+
else
128+
console.log(response.headers);
129+
});
130+
131+
```
132+
83133
### Data collection opt-out
84134

85135
By default, [all requests are logged](https://console.bluemix.net/docs/services/watson/getting-started-logging.html). This can be disabled of by setting the `X-Watson-Learning-Opt-Out` header when creating the service instance:

assistant/v1.ts

Lines changed: 279 additions & 185 deletions
Large diffs are not rendered by default.

conversation/v1-generated.ts

Lines changed: 245 additions & 151 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)