endpoint.blade.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. ## {{ $route['metadata']['title'] ?: $route['uri']}}
  2. @component('scribe::components.badges.auth', ['authenticated' => $route['metadata']['authenticated']])
  3. @endcomponent
  4. {!! $route['metadata']['description'] ?: ''!!}
  5. > Example request:
  6. @foreach($settings['languages'] as $language)
  7. @include("scribe::partials.example-requests.$language")
  8. @endforeach
  9. @if(in_array('GET',$route['methods']) || (isset($route['showresponse']) && $route['showresponse']))
  10. @foreach($route['responses'] as $response)
  11. > Example response ({{$response['description'] ?? $response['status']}}):
  12. ```json
  13. @if(is_object($response['content']) || is_array($response['content']))
  14. {!! json_encode($response['content'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
  15. @elseif(is_string($response['content']) && \Str::startsWith($response['content'], "<<binary>>"))
  16. <Binary data> - {{ str_replace("<<binary>>","",$response['content']) }}
  17. @elseif($response['status'] == 204)
  18. <Empty response>
  19. @elseif(is_string($response['content']) && json_decode($response['content']) == null && $response['content'] !== null)
  20. {{-- If response is a non-JSON string, just print it --}}
  21. {!! $response['content'] !!}
  22. @else
  23. {!! json_encode(json_decode($response['content']), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
  24. @endif
  25. ```
  26. @endforeach
  27. @endif
  28. <div id="execution-results-{{ $endpointId }}" hidden>
  29. <blockquote>Received response<span id="execution-response-status-{{ $endpointId }}"></span>:</blockquote>
  30. <pre class="json"><code id="execution-response-content-{{ $endpointId }}"></code></pre>
  31. </div>
  32. <div id="execution-error-{{ $endpointId }}" hidden>
  33. <blockquote>Request failed with error:</blockquote>
  34. <pre><code id="execution-error-message-{{ $endpointId }}"></code></pre>
  35. </div>
  36. <form id="form-{{ $endpointId }}" data-method="{{ $route['methods'][0] }}" data-path="{{ $route['uri'] }}" data-authed="{{ $route['metadata']['authenticated'] ? 1 : 0 }}" data-hasfiles="{{ count($route['fileParameters']) }}" data-headers='@json($route['headers'])' onsubmit="event.preventDefault(); executeTryOut('{{ $endpointId }}', this);">
  37. <h3>
  38. Request&nbsp;&nbsp;&nbsp;
  39. @if($settings['interactive'])
  40. <button type="button" style="background-color: #8fbcd4; padding: 5px 10px; border-radius 5px; border-width: thin;" id="btn-tryout-{{ $endpointId }}" onclick="tryItOut('{{ $endpointId }}');">Try it out ⚡</button>
  41. @endif
  42. <button type="button" style="background-color: #c97a7e; padding: 5px 10px; border-radius 5px; border-width: thin;" id="btn-canceltryout-{{ $endpointId }}" onclick="cancelTryOut('{{ $endpointId }}');" hidden>Cancel</button>&nbsp;&nbsp;
  43. <button type="submit" style="background-color: #6ac174; padding: 5px 10px; border-radius 5px; border-width: thin;" id="btn-executetryout-{{ $endpointId }}" hidden>Send Request 💥</button>
  44. </h3>
  45. @foreach($route['methods'] as $method)
  46. <p>
  47. @component('scribe::components.badges.http-method', ['method' => $method])@endcomponent <b><code>{{$route['uri']}}</code></b>
  48. </p>
  49. @endforeach
  50. @if($route['metadata']['authenticated'] && $auth['location'] === 'header')
  51. <p>
  52. <label id="auth-{{ $endpointId }}" hidden>{{ $auth['name'] }} header: <b><code>{{ $auth['prefix'] }}</code></b><input type="text" name="{{ $auth['name'] }}" data-prefix="{{ $auth['prefix'] }}" data-endpoint="{{ $endpointId }}" data-component="header"></label>
  53. </p>
  54. @endif
  55. @if(count($route['urlParameters']))
  56. <h4 class="fancy-heading-panel"><b>URL Parameters</b></h4>
  57. @foreach($route['urlParameters'] as $attribute => $parameter)
  58. <p>
  59. @component('scribe::components.field-details', [
  60. 'name' => $parameter['name'],
  61. 'type' => $parameter['type'] ?? 'string',
  62. 'required' => $parameter['required'] ?? true,
  63. 'description' => $parameter['description'],
  64. 'endpointId' => $endpointId,
  65. 'component' => 'url',
  66. ])
  67. @endcomponent
  68. </p>
  69. @endforeach
  70. @endif
  71. @if(count($route['queryParameters']))
  72. <h4 class="fancy-heading-panel"><b>Query Parameters</b></h4>
  73. @foreach($route['queryParameters'] as $attribute => $parameter)
  74. <p>
  75. @component('scribe::components.field-details', [
  76. 'name' => $parameter['name'],
  77. 'type' => $parameter['type'] ?? 'string',
  78. 'required' => $parameter['required'] ?? true,
  79. 'description' => $parameter['description'],
  80. 'endpointId' => $endpointId,
  81. 'component' => 'query',
  82. ])
  83. @endcomponent
  84. </p>
  85. @endforeach
  86. @endif
  87. @if(count($route['nestedBodyParameters']))
  88. <h4 class="fancy-heading-panel"><b>Body Parameters</b></h4>
  89. @component('scribe::partials.body-parameters', ['parameters' => $route['nestedBodyParameters'], 'endpointId' => $endpointId,])
  90. @endcomponent
  91. @endif
  92. </form>
  93. @if(count($route['responseFields'] ?? []))
  94. ### Response
  95. <h4 class="fancy-heading-panel"><b>Response Fields</b></h4>
  96. @foreach($route['responseFields'] as $name => $field)
  97. <p>
  98. @component('scribe::components.field-details', [
  99. 'name' => $field['name'],
  100. 'type' => $field['type'],
  101. 'required' => true,
  102. 'description' => $field['description'],
  103. 'isInput' => false,
  104. ])
  105. @endcomponent
  106. </p>
  107. @endforeach
  108. @endif