Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import '../src/custom-element.js';
import '../src/http-request.js';
export default
{ title: 'http-request', component: 'http-request'
, argTypes:
{ tag: { control: 'text', defaultValue: 'hr-test-component' }
// http-request props
, slice: { control: 'text', type: { name: 'string', required: true }, defaultValue: `page` }
, url: { control: 'text', type: { name: 'string', required: true }, defaultValue: `https://pokeapi.co/api/v2/pokemon?limit=6` }
}
};
function Template( { title, tag , slice, url } )
{
return `
<fieldset>
<legend>${title}</legend>
<custom-element
tag="${ tag }"
hidden
>
<template><!-- wrapping into template to prevent images loading within DCE declaration -->
<http-request
url="${url}"
slice="${slice}"
></http-request>
<xsl:if test="not(//slice/${slice}/data/results/*)">
<h3>loading...</h3>
</xsl:if>
<xsl:for-each select="//slice/${slice}/data/results/*">
<xsl:variable name="pokeid"
select="substring-before( substring-after( @url, 'https://pokeapi.co/api/v2/pokemon/'),'/')"
></xsl:variable>
<button>
<xsl:value-of select='@name'/>
</button>
</xsl:for-each>
</template>
</custom-element>
<${ tag }></${ tag }>
</fieldset>
`;
}
export const
Demo = Template.bind( {} );
Demo.args={title:"url and slice"};
export const
LifecycleInitialized = ()=>`
<fieldset>
<legend>http-request with delayed response</legend>
<p> Before the data become available the <b>request</b>
is populated into dedicated <b>slice</b> in <b>10</b> seconds in this demo
</p>
<custom-element
tag="no-responce"
hidden
>
<template><!-- wrapping into template to prevent images loading within DCE declaration -->
<http-request
url="https://pokeapi.co/api/v2/noreturn"
slice="request_slice"
type="text"
></http-request>
Content of <code>//slice/request_slice</code> before <b>response</b> available
<xsl:for-each select="//slice/request_slice/*">
<ul>
<var data-testid="request-section"><xsl:value-of select='name(.)'/></var>
<xsl:for-each select="@*">
<div>
<var data-testid="section-attribute">@<xsl:value-of select='local-name(.)'/></var>
=
<code><xsl:value-of select='.'/></code>
</div>
</xsl:for-each>
</ul>
</xsl:for-each>
</template>
</custom-element>
<no-responce></no-responce>
</fieldset>
`;
export const
RequestResponceHeaders = ({url})=>`
<fieldset>
<legend>http-request headers and responce status and headers</legend>
<p> <b>request</b> headers are populated into dedicated <b>slice/request/headers</b>
</p>
<custom-element
tag="headers-demo"
hidden
>
<http-request
url="${url}"
slice="request_slice"
type="text"
mode="cors"
header-x-test="testing"
></http-request>
Content of <code>//slice/request_slice</code> is filled by <b>request</b> and <b>response</b>
from <code>${url}</code>
<h3>Samples</h3>
<table>
<tr><th>//slice/request_slice/request/headers/@mode</th>
<td><xsl:value-of select="//slice/request_slice/request/@mode"/></td></tr>
<tr><th>//slice/request_slice/response/headers/@content-type</th>
<td><xsl:value-of select="//slice/request_slice/response/headers/@content-type"/></td></tr>
<tr><th>//slice/request_slice/response/@status</th>
<td><xsl:value-of select="//slice/request_slice/response/@status"/></td></tr>
</table>
<xsl:for-each select="//slice/request_slice/*">
<ul data-request-section="{name(.)}">
<b data-testid="request-section"><xsl:value-of select='name(.)'/></b>
<xsl:for-each select="@*">
<div>
<var data-testid="section-attribute">@<xsl:value-of select='local-name(.)'/></var>
=
<code><xsl:value-of select='.'/></code>
</div>
</xsl:for-each>
<xsl:for-each select="*">
<div>
<b data-testid="section-deep"><xsl:value-of select='local-name(.)'/></b>
<ul>
<xsl:for-each select="@*">
<li>
<var data-testid="section-attribute">@<xsl:value-of select='local-name(.)'/></var>
=
<code><xsl:value-of select='.'/></code>
</li>
</xsl:for-each>
<code><xsl:value-of select='.'/></code>
</ul>
</div>
</xsl:for-each>
</ul>
</xsl:for-each>
</custom-element>
<headers-demo></headers-demo>
</fieldset>
`;
RequestResponceHeaders.args =
{ url: "https://pokeapi.co/api/v2/reflect"
};
|