@php use Illuminate\Support\Str; $fullUrl = ($baseUrl ?? url('/api/application-integration')) . $path; $jsonBody = $body !== null ? json_encode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) : null; $jsonResponse = $response !== null ? json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) : null; $id = 'code-' . Str::random(6); $methodLower = strtolower($method); $jsBody = $jsonBody ? "\n ,body: JSON.stringify($jsonBody)" : ''; $pyBody = $jsonBody ? "payload = $jsonBody\nresponse = requests.request(\"$method\", url, headers=headers, json=payload)" : "payload = None\nresponse = requests.request(\"$method\", url, headers=headers)"; $phpBody = $jsonBody ? "'json' => $jsonBody," : "'json' => new stdClass(),"; $javaBody = $jsonBody ? ".method(\"$method\", HttpRequest.BodyPublishers.ofString(\"" . addslashes($jsonBody) . "\"))" : ".method(\"$method\", HttpRequest.BodyPublishers.noBody())"; $goInit = $jsonBody ? "body := []byte(`$jsonBody`)" : "var body []byte"; $goBuffer = "bytes.NewBuffer(body)"; $dartBody = $jsonBody ? " body: jsonEncode($jsonBody),\n" : ""; $samples = [ 'js' => <<', 'Accept': 'application/json', 'Content-Type': 'application/json', }{$jsBody} }); const data = await res.json(); console.log(data); CODE, 'python' => <<", "Accept": "application/json", "Content-Type": "application/json", } {$pyBody} print(response.json()) CODE, 'php' => <<request('$method', '$fullUrl', [ 'headers' => [ 'Authorization' => 'Bearer ', 'Accept' => 'application/json', 'Content-Type' => 'application/json', ], {$phpBody} ]); echo \$response->getBody(); CODE, 'java' => <<") .header("Content-Type", "application/json") {$javaBody} .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); CODE, 'go' => <<") req.Header.Set("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() fmt.Println(res.Status) } CODE, 'dart' => <<', 'Content-Type': 'application/json', }, {$dartBody} ); print(res.statusCode); print(res.body); } CODE, ]; @endphp
@foreach($samples as $lang => $code) @endforeach
@foreach($samples as $lang => $code)
{{ $code }}
@if($jsonResponse && $loop->first)

// Response
{{ $jsonResponse }}
@endif
@endforeach