api-console-assets
Version:
This repo only exists to publish api console components to npm
101 lines (91 loc) • 3.53 kB
HTML
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<title>response-view demo</title>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../iron-demo-helpers/demo-pages-shared-styles.html">
<link rel="import" href="../../iron-demo-helpers/demo-snippet.html">
<link rel="import" href="../../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../../paper-input/paper-input.html">
<link rel="import" href="../../paper-button/paper-button.html">
<link rel="import" href="../../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../../paper-toast/paper-toast.html">
<link rel="import" href="../response-view.html">
<style is="custom-style" include="demo-pages-shared-styles">
.vertical-section-container {
max-width: 600px;
}
.url-input {
@apply(--layout-horizontal);
}
.url-input paper-input {
@apply(--layout-flex);
}
</style>
</head>
<body unresolved>
<div class="vertical-section-container centered">
<h3>The `response-view`</h3>
<demo-snippet>
<template is="dom-bind">
<div class="url-input">
<paper-input label="URL" value="{{url}}"></paper-input>
<paper-button raised on-tap="download">go</paper-button>
</div>
<response-view request="[[request]]" response="[[response]]" loading-time="[[loadingTime]]" is-xhr response-error="[[responseError]]"></response-view>
</template>
</demo-snippet>
<paper-toast text=""></paper-toast>
</div>
<script>
var scope = document.querySelector('template[is="dom-bind"]');
scope.url = 'https://cdn.rawgit.com/jarrodek/ChromeRestClient/develop/tasks/test-data/xml1.xml';
// scope.url = 'https://raw.githubusercontent.com/jarrodek/ChromeRestClient/develop/tasks/test-data/json2.json';
scope.download = function() {
scope.response = undefined;
scope.responseError = undefined;
scope.loadingTime = 0;
var demoHeaders = new Headers();
demoHeaders.append('accept', 'application/xml');
var opts = {
method: 'GET',
mode: 'cors',
headers: demoHeaders,
bodyUsed: false
};
scope.request = new Request(scope.url, opts);
var start = Date.now();
fetch(scope.url, opts)
.then(function(response) {
scope.response = response;
scope.loadingTime = Date.now() - start;
if (!response.ok) {
scope.responseError = new Error('Unable to make a connection');
} else {
scope.responseError = undefined;
}
})
.catch(function(e) {
scope.response = undefined;
scope.responseError = new Error(e.message);
var toast = document.querySelector('paper-toast');
toast.text = e.message;
toast.opened = true;
console.log(e);
});
};
</script>
</body>
</html>