Sfoglia il codice sorgente

Adjusted language examples to properly display application/x-www-form-urlencoded requests.

Richard Dubiel 3 anni fa
parent
commit
46fb3a8b3d

+ 5 - 1
resources/views/partials/example-requests/bash.md.blade.php

@@ -23,7 +23,11 @@ curl --request {{$endpoint->httpMethods[0]}} \
 @endforeach
 @endforeach
 @elseif(count($endpoint->cleanBodyParameters))
+@if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded')
+    --data "{!! http_build_query($endpoint->cleanBodyParameters, '', '&') !!}"
+@else
     --data "{!! addslashes(json_encode($endpoint->cleanBodyParameters, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)) !!}"
 @endif
+@endif
 
-```
+```

+ 10 - 2
resources/views/partials/example-requests/javascript.md.blade.php

@@ -37,7 +37,11 @@ body.append('{!! $key !!}', document.querySelector('input[name="{!! $key !!}"]')
 @endforeach
 @endforeach
 @elseif(count($endpoint->cleanBodyParameters))
-let body = {!! json_encode($endpoint->cleanBodyParameters, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!}
+@if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded')
+let body = "{!! http_build_query($endpoint->cleanBodyParameters, '', '&') !!}";
+@else
+let body = {!! json_encode($endpoint->cleanBodyParameters, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) !!};
+@endif
 @endif
 
 fetch(url, {
@@ -48,7 +52,11 @@ fetch(url, {
 @if($endpoint->hasFiles())
     body,
 @elseif(count($endpoint->cleanBodyParameters))
+@if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded')
+    body: body,
+@else
     body: JSON.stringify(body),
 @endif
+@endif
 }).then(response => response.json());
-```
+```

+ 5 - 1
resources/views/partials/example-requests/php.md.blade.php

@@ -38,7 +38,11 @@ unset($headers['Content-Type']);
 @endforeach
         ],
 @elseif(!empty($endpoint->cleanBodyParameters))
+@if ($endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded')
+        'form_params' => {!! u::printPhpValue($endpoint->cleanBodyParameters, 8) !!},
+@else
         'json' => {!! u::printPhpValue($endpoint->cleanBodyParameters, 8) !!},
+@endif
 @endif
     ]
 );
@@ -47,4 +51,4 @@ $response = $client->{{ strtolower($endpoint->httpMethods[0]) }}('{{ rtrim($base
 @endif
 $body = $response->getBody();
 print_r(json_decode((string) $body));
-```
+```

+ 2 - 2
resources/views/partials/example-requests/python.md.blade.php

@@ -38,10 +38,10 @@ headers = {
 $optionalArguments = [];
 if (count($endpoint->headers)) $optionalArguments[] = "headers=headers";
 if (count($endpoint->fileParameters)) $optionalArguments[] = "files=files";
-if (count($endpoint->cleanBodyParameters)) $optionalArguments[] = (count($endpoint->fileParameters) ? "data=payload" : "json=payload");
+if (count($endpoint->cleanBodyParameters)) $optionalArguments[] = (count($endpoint->fileParameters) || $endpoint->headers['Content-Type'] == 'application/x-www-form-urlencoded' ? "data=payload" : "json=payload");
 if (count($endpoint->cleanQueryParameters)) $optionalArguments[] = "params=params";
 $optionalArguments = implode(', ',$optionalArguments);
 @endphp
 response = requests.request('{{$endpoint->httpMethods[0]}}', url, {{ $optionalArguments }})
 response.json()
-```
+```