You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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
@@ -80,6 +82,54 @@ See the `examples/` folder for [Browserify](http://browserify.org/) and [Webpack
80
82
Note: not all services currently support CORS, and therefore not all services can be used client-side.
81
83
Of those that do, most require an auth token to be generated server-side via the [Authorization Service](#authorization).
82
84
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 =newwatson.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:
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:
0 commit comments