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
Copy file name to clipboardExpand all lines: docs/cors.md
+3-186Lines changed: 3 additions & 186 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,192 +38,9 @@ This configuration changes the request endpoint from `http://domain.com/path/?qu
38
38
39
39
The proxy URL won't be visible by the user. The user can't do anything to change this behavior unless your application includes a custom UI that supports such a change.
40
40
41
-
## Handling HTTP request by the hosting website / application
41
+
## Handling HTTP request by the hosting application
42
42
43
-
When the user runs the request from the "try it" screen, API Console fires the `api-console-request`[custom event](https://developer.mozilla.org/en/docs/Web/API/CustomEvent). If your application can handle the transport (by providing a proxy, for example), listen for this event, and cancel it by calling `event.preventDefault()`. If the event is cancelled, API Console listens for the `api-console-response` custom
43
+
When the user runs the request from the "try it" screen, API Console fires the `api-request`[custom event](https://developer.mozilla.org/en/docs/Web/API/CustomEvent). If your application can handle the transport (by providing a proxy, for example), listen for this event, and cancel it by calling `event.preventDefault()`. If the event is cancelled, API Console listens for the `api-response` custom
44
44
event that should contain response details. Otherwise, the console uses the build in fallback function to get the resource using Fetch API / XHR.
45
45
46
-
#### api-console-request custom event
47
-
48
-
The Event `detail` object contains following properties:
49
-
50
-
Property | Type | Description
51
-
----------------|-------------|----------
52
-
`url` | `String` | The request URL. If proxy is set, it will be the final URL with the proxy value.
53
-
`method` | `String` | The HTTP method
54
-
`headers` | `String` | HTTP headers string to send with the message
55
-
`payload` | `String` | Body to send
56
-
57
-
#### api-console-response
58
-
59
-
This event must be fired when the hosting app finishes the request. It must contain a generated Request
60
-
and Response object as defined in the [Fetch specification](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch). API Console includes a polyfill for the Fetch API.
61
-
62
-
Property | Type | Description
63
-
----------------|-------------|----------
64
-
`request` | `Request` | The request object as defined in the Fetch API spec. See [Request docs](https://developer.mozilla.org/en-US/docs/Web/API/Request) for more information.
65
-
`response` | `Response` | The response object as defined in the Fetch API spec. See [Response docs](https://developer.mozilla.org/en-US/docs/Web/API/Response) for more information.
66
-
`isXhr` | `Boolean` | Default is `true`. Indicates that the transport method doesn't support advanced timings and redirects information. See [request-panel](https://elements.advancedrestclient.com/elements/raml-request-panel) documentation for more information.
67
-
`error` | `Error` | When the request / response encounters an error (`request.ok` equals `false`), the error object is set with the human readable message for the user.
68
-
69
-
#### Example with handling request / response events
70
-
71
-
```javascript
72
-
// Start time of executing the request
73
-
var startTime;
74
-
// Initial request data passed by the event.
75
-
var requestData;
76
-
/**
77
-
* Creates a Headers object based on the HTTP headers string.
78
-
*
79
-
* @param{String}headers HTTP headers.
80
-
* @return{Headers} Parsed headers object.
81
-
*/
82
-
functioncreateHeaders(headers) {
83
-
if (!headers) {
84
-
returnnewHeaders();
85
-
}
86
-
var result =newHeaders();
87
-
var list =headers.split('\n').map(function(line) {
88
-
var _parts =line.split(':');
89
-
var _name = _parts[0];
90
-
var _value = _parts[1];
91
-
_name = _name ?_name.trim() :null;
92
-
_value = _value ?_value.trim() :null;
93
-
if (!_name ||!_value) {
94
-
returnnull;
95
-
}
96
-
return {
97
-
name: _name,
98
-
value: _value
99
-
};
100
-
}).filter(function(item) {
101
-
return!!item;
102
-
});
103
-
list.forEach(function(item) {
104
-
result.append(item.name, item.value);
105
-
});
106
-
return result;
107
-
}
108
-
/**
109
-
* Creates a request object from the event's request data.
110
-
*
111
-
* @param{Object}data Latest request data as in the `api-console-request` object event.
112
-
* @return{Request} The Request object.
113
-
*/
114
-
functioncreateRequest(data) {
115
-
var init = {
116
-
method:data.method,
117
-
mode:'cors'
118
-
};
119
-
if (data.headers) {
120
-
init.headers=createHeaders(data.headers);
121
-
}
122
-
if (['GET', 'HEAD'].indexOf(data.method) !==-1) {
123
-
data.payload=undefined;
124
-
} else {
125
-
if (data.payload) {
126
-
init.body=data.payload;
127
-
}
128
-
}
129
-
returnnewRequest(data.url, init);
130
-
}
131
-
/**
132
-
* Creates a response object from the response data.
133
-
* If the response is invalid then returned Response object will be errored.
134
-
*
135
-
* @param{XMLHttpRequest}xhr The XHR object used to make a connection.
See https://github.com/advanced-rest-client/api-components-api/blob/master/docs/api-request-and-response.md for detailed documentation of the request events.
Copy file name to clipboardExpand all lines: docs/gh-pages.md
+3-11Lines changed: 3 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,9 @@ This example shows how to use Travis-CI to push API Console with the API documen
6
6
7
7
## Overview
8
8
9
-
[docs/gh-pages/.travis.yml](gh-pages/.travis.yml) file contains a set of directives that Travis understands and executes. This file contains a minimal setup for the API console generation but you can change it.
9
+
[docs/gh-pages/.travis.yml](gh-pages/.travis.yml) file contains a set of directives that Travis understands and executes. This file contains a minimal setup for the API console generation.
10
10
11
-
First, Travis installs node dependencies, which in this case is the
12
-
[api-console-builder](https://www.npmjs.com/package/api-console-builder) module as defined in the [docs/gh-pages/package.json](gh-pages/package.json) file:
13
-
14
-
```yaml
15
-
before_script:
16
-
- npm install
17
-
```
18
-
19
-
Next, Travis executes [docs/gh-pages/deploy.sh](gh-pages/deploy.sh) that processes your private key associated with a GitHub account, as discussed below. Finally, Travis checks out the latest version of your API, creates the console, and publishes the console in `gh-pages` branch.
11
+
Travis executes [docs/gh-pages/deploy.sh](gh-pages/deploy.sh) that processes your private key associated with a GitHub account, as discussed below. Finally, Travis checks out the latest version of your API, creates the console, and publishes the console in `gh-pages` branch.
20
12
21
13
```yaml
22
14
script: bash ./deploy.sh
@@ -44,7 +36,7 @@ If you already have generated keys, go to step 5.
44
36
```
45
37
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): /Users/you/.ssh/gh-travis_rsa
46
38
```
47
-
We use this filename in the build script.
39
+
We use this filename in the build script.
48
40
49
41
4. Do _not_ set a password. When Travis runs the script there's no way to respond to a password prompt. Consequently, do not use this key for any other purpose. Doing so would be unsafe. Also, keep the key in a location that nobody can access.
0 commit comments