endpoint.blade.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. @php
  2. /** @var Knuckles\Camel\Output\OutputEndpointData $endpoint */
  3. @endphp
  4. <h2 id="{!! $endpoint->fullSlug() !!}">{{ $endpoint->name() }}</h2>
  5. <p>
  6. @component('scribe::components.badges.auth', ['authenticated' => $endpoint->isAuthed()])
  7. @endcomponent
  8. </p>
  9. {!! Parsedown::instance()->text($endpoint->metadata->description ?: '') !!}
  10. <span id="example-requests-{!! $endpoint->endpointId() !!}">
  11. <blockquote>Example request:</blockquote>
  12. @foreach($metadata['example_languages'] as $language)
  13. <div class="{{ $language }}-example">
  14. @include("scribe::partials.example-requests.$language")
  15. </div>
  16. @endforeach
  17. </span>
  18. <span id="example-responses-{!! $endpoint->endpointId() !!}">
  19. @if($endpoint->isGet() || $endpoint->hasResponses())
  20. @foreach($endpoint->responses as $response)
  21. <blockquote>
  22. <p>Example response ({{$response->description ?: $response->status}}):</p>
  23. </blockquote>
  24. @if(count($response->headers))
  25. <details class="annotation">
  26. <summary style="cursor: pointer;">
  27. <small onclick="textContent = parentElement.parentElement.open ? 'Show headers' : 'Hide headers'">Show headers</small>
  28. </summary>
  29. <pre><code class="language-http">@foreach($response->headers as $header => $value)
  30. {{ $header }}: {{ is_array($value) ? implode('; ', $value) : $value }}
  31. @endforeach </code></pre></details> @endif
  32. <pre>
  33. @if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
  34. <code>[Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code>
  35. @elseif($response->status == 204)
  36. <code>[Empty response]</code>
  37. @else
  38. @php($parsed = json_decode($response->content))
  39. {{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
  40. <code class="language-json" style="max-height: 300px;">{!! htmlentities($parsed != null ? json_encode($parsed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : $response->content) !!}</code>
  41. @endif </pre>
  42. @endforeach
  43. @endif
  44. </span>
  45. <span id="execution-results-{{ $endpoint->endpointId() }}" hidden>
  46. <blockquote>Received response<span
  47. id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
  48. </blockquote>
  49. <pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}" style="max-height: 400px;"></code></pre>
  50. </span>
  51. <span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
  52. <blockquote>Request failed with error:</blockquote>
  53. <pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
  54. </span>
  55. <form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->httpMethods[0] }}"
  56. data-path="{{ $endpoint->uri }}"
  57. data-authed="{{ $endpoint->isAuthed() ? 1 : 0 }}"
  58. data-hasfiles="{{ $endpoint->hasFiles() ? 1 : 0 }}"
  59. data-isarraybody="{{ $endpoint->isArrayBody() ? 1 : 0 }}"
  60. autocomplete="off"
  61. onsubmit="event.preventDefault(); executeTryOut('{{ $endpoint->endpointId() }}', this);">
  62. <h3>
  63. Request&nbsp;&nbsp;&nbsp;
  64. @if($metadata['try_it_out']['enabled'] ?? false)
  65. <button type="button"
  66. style="background-color: #8fbcd4; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  67. id="btn-tryout-{{ $endpoint->endpointId() }}"
  68. onclick="tryItOut('{{ $endpoint->endpointId() }}');">Try it out ⚡
  69. </button>
  70. <button type="button"
  71. style="background-color: #c97a7e; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  72. id="btn-canceltryout-{{ $endpoint->endpointId() }}"
  73. onclick="cancelTryOut('{{ $endpoint->endpointId() }}');" hidden>Cancel 🛑
  74. </button>&nbsp;&nbsp;
  75. <button type="submit"
  76. style="background-color: #6ac174; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  77. id="btn-executetryout-{{ $endpoint->endpointId() }}" hidden>Send Request 💥
  78. </button>
  79. @endif
  80. </h3>
  81. @foreach($endpoint->httpMethods as $method)
  82. <p>
  83. @component('scribe::components.badges.http-method', ['method' => $method])@endcomponent
  84. <b><code>{{$endpoint->uri}}</code></b>
  85. </p>
  86. @endforeach
  87. @if(count($endpoint->headers))
  88. <h4 class="fancy-heading-panel"><b>Headers</b></h4>
  89. @foreach($endpoint->headers as $name => $example)
  90. <?php
  91. $htmlOptions = [];
  92. if ($endpoint->isAuthed() && $metadata['auth']['location'] == 'header' && $metadata['auth']['name'] == $name) {
  93. $htmlOptions = [ 'class' => 'auth-value', ];
  94. }
  95. ?>
  96. <p>
  97. @component('scribe::components.field-details', [
  98. 'name' => $name,
  99. 'type' => null,
  100. 'required' => true,
  101. 'description' => null,
  102. 'example' => $example,
  103. 'endpointId' => $endpoint->endpointId(),
  104. 'component' => 'header',
  105. 'isInput' => true,
  106. 'html' => $htmlOptions,
  107. ])
  108. @endcomponent
  109. </p>
  110. @endforeach
  111. @endif
  112. @if(count($endpoint->urlParameters))
  113. <h4 class="fancy-heading-panel"><b>URL Parameters</b></h4>
  114. @foreach($endpoint->urlParameters as $attribute => $parameter)
  115. <p>
  116. @component('scribe::components.field-details', [
  117. 'name' => $parameter->name,
  118. 'type' => $parameter->type ?? 'string',
  119. 'required' => $parameter->required,
  120. 'description' => $parameter->description,
  121. 'example' => $parameter->example ?? '',
  122. 'endpointId' => $endpoint->endpointId(),
  123. 'component' => 'url',
  124. 'isInput' => true,
  125. ])
  126. @endcomponent
  127. </p>
  128. @endforeach
  129. @endif
  130. @if(count($endpoint->queryParameters))
  131. <h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
  132. @foreach($endpoint->queryParameters as $attribute => $parameter)
  133. <?php
  134. $htmlOptions = [];
  135. if ($endpoint->isAuthed() && $metadata['auth']['location'] == 'query' && $metadata['auth']['name'] == $attribute) {
  136. $htmlOptions = [ 'class' => 'auth-value', ];
  137. }
  138. ?>
  139. <p>
  140. @component('scribe::components.field-details', [
  141. 'name' => $parameter->name,
  142. 'type' => $parameter->type,
  143. 'required' => $parameter->required,
  144. 'description' => $parameter->description,
  145. 'example' => $parameter->example ?? '',
  146. 'endpointId' => $endpoint->endpointId(),
  147. 'component' => 'query',
  148. 'isInput' => true,
  149. 'html' => $htmlOptions,
  150. ])
  151. @endcomponent
  152. </p>
  153. @endforeach
  154. @endif
  155. @if(count($endpoint->nestedBodyParameters))
  156. <h4 class="fancy-heading-panel"><b>Body Parameters</b></h4>
  157. <x-scribe::nested-fields
  158. :fields="$endpoint->nestedBodyParameters" :endpointId="$endpoint->endpointId()"
  159. />
  160. @endif
  161. </form>
  162. @if(count($endpoint->responseFields))
  163. <h3>Response</h3>
  164. <h4 class="fancy-heading-panel"><b>Response Fields</b></h4>
  165. <x-scribe::nested-fields
  166. :fields="$endpoint->nestedResponseFields" :endpointId="$endpoint->endpointId()"
  167. :isInput="false"
  168. />
  169. @endif