Tag: <raml-request-panel>
Using bower:
bower install --save advanced-rest-client/raml-request-panel
The request panel view for the request defined as a RAML method. It is a main view element for the API console to display the request panel related to the RAML specification.
The element has it's own XHR / Fetch transport method and it will be used if the hostng application
do not handle the api-console-request
event.
When the user request to make the HTTP request then cancellable api-console-request
event will
be fired with the request details (see below).
The hosting application, if it about to use different transport method, should cancel the event by
calling preventDefault()
function on the event (and possibly stopPropagation()
) and handle the
request. If the event was not prevented (canceled) then internall Fetch/XHR will be used.
When the request is ready then the hosting app must fire the api-console-response
event with
created Request and Response objects. This element listens on the window
property for the
api-console-response
event.
This event is fired when the user request to make a HTTP request.
This event will have the following properties set on the detail
object:
Property | Type | Description |
---|---|---|
url |
String | The request URL |
method |
String | The HTTP method |
headers |
String | Headers to send |
payload |
String | Payload to send |
auth |
Object | Optional. For some authorization methodss (like NTLM) the authorization header or query param can't be set and the authorization must be made on the connection. In this cases the auth object will be set with type and settings properties. While type is the name of the authorization method, the settings object depends on the authorization method and may vary. Detailed documentation for the auth methods is in the auth-methods element. |
This event must be fired when the hosring app finish the request. It must contains generated Request and Response object according to the Fetch specification.
Becaue the Fetch API is a new API not all browsers support it. In this case the polyfill must be used
in the hosted app. Add the fetch-polyfill
element (advanced-rest-client/fetch-polyfill) to the
hosted app to have the support. It is recommended to use this element so the polyfill will be loaded
only once. See the raml-request-panel-simple-xhr
element for example implementation.
Property | Type | Description |
---|---|---|
request |
Object | The request object as defined in the Fetch API spec. |
response |
Object | The response object as defined in the Fetch API spec. |
isXhr |
Boolean | If not set the element assumes it's true. Indicated if the transport method doesn't support advanced timings and redirects information. See below. |
error |
Error | When the request / response is errored (request.ok equals false ) then the error object should be set with the human readable message that will be displayed to the user. |
loadingTime |
Number | The response full loading time |
See Advanced transport options
for more event options.
<raml-request-panel
method="[[ramlMethod]]"
redirect-url="http://oauth.redirect.url"
request="{{request}}"
response="{{response}}"
response-error="{{responseError}}"
loading-time="{{loadingTime}}"></raml-request-panel>
The response panel in the ARC elements is able to display the response in simple and advanced view.
Simple is meant to be used when the HTTP request has been made by the simple transports like XHR or Fetch. It just displays the response status, headers and paylaod.
Advanced view is reserved for transport methods that are able to generate additional informations about the request and resposne. This information is timings for the request/response, timings for the redirects and information about redirects.
When the advanced options are set then the isXhr
flag on the api-console-response
event's detail
object must be set to true.
The timings
propery added to the api-console-response
is the request / response timings as
defined in HAR 1.2 spec. For example:
"timings": {
"blocked": 0,
"dns": -1,
"connect": 15,
"send": 20,
"wait": 38,
"receive": 12,
"ssl": -1,
"comment": ""
}
If the timings
property is set the loadingTime
property is optional since it will be calculated
from the detailed timing.
The redirectTimings
propery added to the api-console-response
is the list of the timings
objects as defined in HAR 1.2 specification.
The list should be ordered list of redirections. For example:
"redirect-timings": [{
"blocked": 0,
"dns": -1,
"connect": 15,
"send": 20,
"wait": 38,
"receive": 12,
"ssl": -1,
"comment": ""
}]
The redirects
property added to the api-console-response
event is the list of objects. Each
object should have the headers
property as a HTTP headers string, status
as a HTTP status
and optionally statusText
. It is consisted with the Response
object except the headers are
String instead of the Headers object.
"redirects": [Response {
"status": 301,
"statusText": "Moved Permanently",
"headers": "Content-lenght: 0"
}]
The HTTP source message sent to the server. It should be full message from the message header to the request body.
var event = new CustomEvent('api-console-response', {
cancelable: true,
bubbles: true,
composed: true,
detail: {
isXhr: true,
request: request,
response: response,
error: new Error('Dummy error'), // Has the response details so it shouldn't be set.
loadingTime: 125, // This is optional because timings is set
timings: { dns: 123, ... }
redirectTimings: [{ dns: 123, ... }],
redirects: [redirectResponse1, ...],
sourceMessage: 'HTTP/1.1 200 OK\n ....'
}
});
document.body.dispatchEvent(event);
<raml-request-panel>
provides the following custom properties and mixins for styling:
Custom property | Description | Default |
---|---|---|
--raml-request-panel |
Mixin applied to the element | {} |
--raml-request-panel-panel-border-color |
Border color of each block in the tabs | rgba(0, 0, 0, 0.24) |
--raml-request-panel-container |
Mixin applied to the main content container | {} |
--raml-request-panel-container-narrow |
Mixin applied to the main content container when layout is narrow | {} |
--action-button |
Mixin applied to the action button | {} |
--action-button-hover |
Mixin applied to :hover state for the action button | {} |
--action-button-disabled |
Mixin applied to disbaled action button | {} |
--primary-color |
background-color of the main action button | --primary-color |
--primary-action-color |
Color of the main action button | --primary-action-color |
--action-accent-button-disabled-color |
Color of disabled action button | `` |
--primary-button-background-color |
Background color of the primary button. | --accent-color |
--primary-button-color |
Font color of the primary button | #fff |
--primary-button-hover-background-color |
Background color of the primary button when hovered. | --accent-color |
--primary-button-hover-color |
Font color of the primary button when hovered. | #fff |
You can set the narrow
property so the element will be rendered in the mobile view.
This property will be propagated to all sub-elements that uses this property to change layout.
- Type:
Object
A RAML node representing a method node in RAML definition. It should be obtained from theraml-path-to-object
element.
- Type:
number
- Default:
0
Selected request tab.
- Type:
string
Current content type.
- Type:
boolean
- Default:
false
- Read only property Computed value if the method can carry a payload
- Type:
string
Headers for the request.
- Type:
string
Body for the request
- Type:
string
Current URL
- Type:
boolean
If set it will renders the view in the narrow layout.
- Type:
string
- Default:
"768px"
A widith below which thenarrow
property will be set to true.
- Type:
boolean
- Default:
false
- Read only property If true then the request is currently loaded.
- Type:
boolean
- Read only property If true then the request was made using the XHR object (it has less data in the response).
- Type:
Request
- Read only property
The request object created by the transport.
It should be the
Request
object as defined in the Fetch API spec. This element provides the polyfill for this API.
- Type:
Response
- Read only property
The response object from the transport.
It should be the
Response
object as defined in the Fetch API spec. This element provides the polyfill for this API.
- Type:
Object
- Read only property Set when the response errored.
- Type:
number
- Read only property Response full loading time.
- Type:
Object
- Read only property
If the transport method is able to collect detailed information about request timings
then this value will be set. It's the
timings
property from the HAR 1.2 spec.
- Type:
Array
- Read only property
If the transport method is able to collect detailed information about redirects timings
then this value will be set. It's a list of
timings
property from the HAR 1.2 spec.
- Type:
Array
- Read only property It will be set if the transport method can generate information about redirections.
- Type:
string
- Read only property Http message sent to the server.
This information should be available only in case of advanced HTTP transport.
- Type:
boolean
Received from the authorization panel state if authorization is required
- Type:
boolean
Received from the authorization panel state if authorization data is valid
- Type:
string
OAuth2 redirect URL
- Type:
string
Selected by the user auth method (if any)
- Type:
Object
Current authorization settings.
- Type:
boolean
Computed value when the URL change. If not valid form submission won't be possible.
- Type:
boolean
Hides the URL editor from the view. The editor is still in the DOM and theurlInvalid
property still will be set.
- Type:
string
A base URI for the API. To be set if RAML spec is missingbaseUri
declaration and this produces invalid URL input. This information is passed to the URL editor that prefixes the URL withbaseUri
value if passed URL is a relative URL.
- Type:
Object
Computed model for query parameters
- Type:
Object
Computed model for URI parameters
- Type:
boolean
Computed value from the parameters model
- Type:
boolean
Computed value from the parameters model
- Type:
boolean
Computed value from the parameters model
- Type:
boolean
- Default:
true
- Read only property Value computed when RAML method change. It is set to true when authorization is not defined for current endpoint's method.
- Return type:
undefined
Execute the request with current settings. This method fires theapi-console-request
so the request can be handled by the hosting app. Hosting app must callevent.preventDefault()
on the event otherwise the console will attempt to make a request usnig XHR object.
- Return type:
undefined
Performs an authorization by bringing up the authorization form in a popup and after successful authorization executes the request.
- Return type:
undefined
Returns an object with the request properties. The object contains: - method (String)
- url (String)
- headers (String)
- payload (String)
- auth (Object)
The auth
property is optional and is only added to the request if simple authorization
header will not work. For example NTLM auth method has to be made on a single socket
connection (authorization and the request) so it can't be made before the request.
The auth
object contains 2 properties:
- type (String) the authorization type - one of from the
auth-methods
element - settings (Object) Authorization parameters entered by the user. It vary and depends on
selected auth method. For example in case of the NTLM it will be:
username
,password
anddomain
.
Tag: <raml-request-panel-simple-xhr>
Using bower:
bower install --save advanced-rest-client/raml-request-panel-simple-xhr
The raml-request-panel-simple-xhr
is an element that executes the request if the hosted app do
not handle the api-console-request
event.
It can be used as a boilerplate for communication with the raml-request-panel
element to handle
request event, execute the request and return the result.
The raml-request-panel
is based on the fetch's API Request and Response object. The returning
event transport them to the source element.
Because the Response object is not intended to carry a custom errors, in case of error, the
Response object only carrying nformation response.ok
equals false
and the error
Error
object is added to the event's detail object.
This element don't listen for the api-console-request
event giving a chance for the hosted app to
handle it. If the hosted app intend to handle the requests it should listen for an event:
window.addEventListener('api-console-request', function(e) {
var data = e.detail;
console.log(data.url);
console.log(data.method);
console.log(data.payload);
console.log(data.headers);
console.log(data.auth); // optional, see `raml-request-panel.serializeRequest()`
});
After the request is made (successfully or not) the api-console-response
event must be fired.
It should have request
and response
objects added to the event's detail
object. If the request
is errored the it must contain additional error
proeprty which is JS' Error object with the human
readable message (it will be displayed as an error message).
Additionaly the detail object can contain the isXhr
property which is set to true be default.
It should be set to false if the request has been made by more than XHR advanced transport which
dives information about timings and redirects.
See the response-panel
for more information.
var event = new CustomEvent('api-console-request', {
cancelable: false,
bubbles: true,
composed: true,
detail: {
request: new Request(...),
response: new Response(body, {status: 200})
}
});
this.dispatchEvent(event);
Becaue the Fetch API is a new API not all browsers support it. Therefore the polyfill must be used
in the hosted app. Add the fetch-polyfill
element (advanced-rest-client/fetch-polyfill) to the
hosted app to have it supported.
Because this element fires back an event it has to be attached to the DOM.
- Type:
boolean
- Default:
false
- Read only property If true then the request is currently loaded.
- Type:
Object
Generated Request object during the latest request
- Type:
Object
Generated Response object during the latest request
- Type:
Object
Generated error object during the latest request
- Type:
number
Total request / response time
- Return type:
undefined
Executes the request.