endpoint.blade.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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->metadata->authenticated])
  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>
  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>
  32. </details> @endif
  33. <pre>
  34. @if(is_string($response->content) && Str::startsWith($response->content, "<<binary>>"))
  35. <code>[Binary data] - {{ htmlentities(str_replace("<<binary>>", "", $response->content)) }}</code>
  36. @elseif($response->status == 204)
  37. <code>[Empty response]</code>
  38. @else
  39. @php($parsed = json_decode($response->content))
  40. {{-- If response is a JSON string, prettify it. Otherwise, just print it --}}
  41. <code class="language-json">{!! htmlentities($parsed != null ? json_encode($parsed, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : $response->content) !!}</code>
  42. @endif </pre>
  43. @endforeach
  44. @endif
  45. </span>
  46. <span id="execution-results-{{ $endpoint->endpointId() }}" hidden>
  47. <blockquote>Received response<span
  48. id="execution-response-status-{{ $endpoint->endpointId() }}"></span>:
  49. </blockquote>
  50. <pre class="json"><code id="execution-response-content-{{ $endpoint->endpointId() }}"></code></pre>
  51. </span>
  52. <span id="execution-error-{{ $endpoint->endpointId() }}" hidden>
  53. <blockquote>Request failed with error:</blockquote>
  54. <pre><code id="execution-error-message-{{ $endpoint->endpointId() }}"></code></pre>
  55. </span>
  56. <form id="form-{{ $endpoint->endpointId() }}" data-method="{{ $endpoint->httpMethods[0] }}"
  57. data-path="{{ $endpoint->uri }}"
  58. data-authed="{{ $endpoint->metadata->authenticated ? 1 : 0 }}"
  59. data-hasfiles="{{ $endpoint->hasFiles() ? 1 : 0 }}"
  60. data-isarraybody="{{ $endpoint->isArrayBody() ? 1 : 0 }}"
  61. data-headers='@json($endpoint->headers)'
  62. autocomplete="off"
  63. onsubmit="event.preventDefault(); executeTryOut('{{ $endpoint->endpointId() }}', this);">
  64. <h3>
  65. Request&nbsp;&nbsp;&nbsp;
  66. @if($metadata['try_it_out']['enabled'] ?? false)
  67. <button type="button"
  68. style="background-color: #8fbcd4; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  69. id="btn-tryout-{{ $endpoint->endpointId() }}"
  70. onclick="tryItOut('{{ $endpoint->endpointId() }}');">Try it out ⚡
  71. </button>
  72. <button type="button"
  73. style="background-color: #c97a7e; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  74. id="btn-canceltryout-{{ $endpoint->endpointId() }}"
  75. onclick="cancelTryOut('{{ $endpoint->endpointId() }}');" hidden>Cancel 🛑
  76. </button>&nbsp;&nbsp;
  77. <button type="submit"
  78. style="background-color: #6ac174; padding: 5px 10px; border-radius: 5px; border-width: thin;"
  79. id="btn-executetryout-{{ $endpoint->endpointId() }}" hidden>Send Request 💥
  80. </button>
  81. @endif
  82. </h3>
  83. @foreach($endpoint->httpMethods as $method)
  84. <p>
  85. @component('scribe::components.badges.http-method', ['method' => $method])@endcomponent
  86. <b><code>{{$endpoint->uri}}</code></b>
  87. </p>
  88. @endforeach
  89. @if($endpoint->metadata->authenticated && $metadata['auth']['location'] === 'header')
  90. <p>
  91. <label id="auth-{{ $endpoint->endpointId() }}" hidden>{{ $metadata['auth']['name'] }} header:
  92. <b><code>{{ $metadata['auth']['prefix'] }}</code></b>
  93. <input type="text"
  94. name="{{ $metadata['auth']['name'] }}"
  95. data-prefix="{{ $metadata['auth']['prefix'] }}"
  96. data-endpoint="{{ $endpoint->endpointId() }}"
  97. data-component="header"></label>
  98. </p>
  99. @endif
  100. @if(count($endpoint->urlParameters))
  101. <h4 class="fancy-heading-panel"><b>URL Parameters</b></h4>
  102. @foreach($endpoint->urlParameters as $attribute => $parameter)
  103. <p>
  104. @component('scribe::components.field-details', [
  105. 'name' => $parameter->name,
  106. 'type' => $parameter->type ?? 'string',
  107. 'required' => $parameter->required,
  108. 'description' => $parameter->description,
  109. 'example' => $parameter->example ?? '',
  110. 'endpointId' => $endpoint->endpointId(),
  111. 'component' => 'url',
  112. 'isInput' => true,
  113. ])
  114. @endcomponent
  115. </p>
  116. @endforeach
  117. @endif
  118. @if(count($endpoint->queryParameters))
  119. <h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
  120. @foreach($endpoint->queryParameters as $attribute => $parameter)
  121. <p>
  122. @component('scribe::components.field-details', [
  123. 'name' => $parameter->name,
  124. 'type' => $parameter->type,
  125. 'required' => $parameter->required,
  126. 'description' => $parameter->description,
  127. 'example' => $parameter->example ?? '',
  128. 'endpointId' => $endpoint->endpointId(),
  129. 'component' => 'query',
  130. 'isInput' => true,
  131. ])
  132. @endcomponent
  133. </p>
  134. @endforeach
  135. @endif
  136. @if(count($endpoint->nestedBodyParameters))
  137. <h4 class="fancy-heading-panel"><b>Body Parameters</b></h4>
  138. <x-scribe::nested-fields
  139. :fields="$endpoint->nestedBodyParameters" :endpointId="$endpoint->endpointId()"
  140. />
  141. @endif
  142. </form>
  143. @if(count($endpoint->responseFields))
  144. <h3>Response</h3>
  145. <h4 class="fancy-heading-panel"><b>Response Fields</b></h4>
  146. <x-scribe::nested-fields
  147. :fields="$endpoint->nestedResponseFields" :endpointId="$endpoint->endpointId()"
  148. :isInput="false"
  149. />
  150. @endif