diff --git a/src/resources/views/partials/route.blade.php b/src/resources/views/partials/route.blade.php index 02e340a6..c1dc3b2c 100644 --- a/src/resources/views/partials/route.blade.php +++ b/src/resources/views/partials/route.blade.php @@ -21,22 +21,24 @@ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "{{ rtrim(config('app.docs_url') ?: config('app.url'), '/') }}/{{ ltrim($parsedRoute['uri'], '/') }}", - "method": "{{$parsedRoute['methods'][0]}}", + +const headers = new Headers({'Accept': 'application/json'}) + +const settings = { + method: "{{$parsedRoute['methods'][0]}}" + credentials: 'include' + headers, @if(count($parsedRoute['parameters'])) -"data": {!! str_replace("\n}","\n }", str_replace(' ',' ',json_encode(array_combine(array_keys($parsedRoute['parameters']), array_map(function($param){ return $param['value']; },$parsedRoute['parameters'])), JSON_PRETTY_PRINT))) !!}, + body: {!! str_replace("\n}","\n }", str_replace(' ',' ',json_encode(array_combine(array_keys($parsedRoute['parameters']), array_map(function($param){ return $param['value']; },$parsedRoute['parameters'])), JSON_PRETTY_PRINT))) !!}, @endif -"headers": { - "accept": "application/json" - } } -$.ajax(settings).done(function (response) { - console.log(response); -}); +const request = new Request("{{ rtrim(config('app.docs_url') ?: config('app.url'), '/') }}/{{ ltrim($parsedRoute['uri'], '/') }}", settings) + +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)) ``` @if(in_array('GET',$parsedRoute['methods']) || (isset($parsedRoute['showresponse']) && $parsedRoute['showresponse'])) diff --git a/tests/Fixtures/index.md b/tests/Fixtures/index.md index 14b0648e..037562a8 100644 --- a/tests/Fixtures/index.md +++ b/tests/Fixtures/index.md @@ -2,17 +2,19 @@ title: API Reference language_tabs: -- bash -- javascript + - bash + - javascript -includes: +? includes search: true toc_footers: -- Documentation Powered by Documentarian + - Documentation Powered by Documentarian --- + + # Info Welcome to the generated API reference. @@ -21,7 +23,9 @@ Welcome to the generated API reference. #general + + ## Example title. This will be the long description. @@ -35,19 +39,20 @@ curl -X GET -G "http://localhost/api/test" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/test", - "method": "GET", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); -$.ajax(settings).done(function (response) { - console.log(response); -}); +const settings = { + method: "GET", + credentials: "include", + headers +}; + +const request = new Request("http://localhost/api/test", settings); + +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); ``` > Example response: @@ -57,12 +62,13 @@ null ``` ### HTTP Request -`GET api/test` +`GET api/test` + ## api/fetch > Example request: @@ -73,19 +79,20 @@ curl -X GET -G "http://localhost/api/fetch" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/fetch", - "method": "GET", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); + +const settings = { + method: "GET", + credentials: "include", + headers +}; + +const request = new Request("http://localhost/api/fetch", settings); -$.ajax(settings).done(function (response) { - console.log(response); -}); +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); ``` > Example response: @@ -101,9 +108,7 @@ $.ajax(settings).done(function (response) { ``` ### HTTP Request -`GET api/fetch` +`GET api/fetch` - - diff --git a/tests/Fixtures/resource_index.md b/tests/Fixtures/resource_index.md index c4b4676f..7c5b894b 100644 --- a/tests/Fixtures/resource_index.md +++ b/tests/Fixtures/resource_index.md @@ -2,17 +2,19 @@ title: API Reference language_tabs: -- bash -- javascript + - bash + - javascript -includes: +? includes search: true toc_footers: -- Documentation Powered by Documentarian + - Documentation Powered by Documentarian --- + + # Info Welcome to the generated API reference. @@ -21,7 +23,9 @@ Welcome to the generated API reference. #general + + ## Display a listing of the resource. > Example request: @@ -32,19 +36,20 @@ curl -X GET -G "http://localhost/api/user" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/user", - "method": "GET", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); + +const settings = { + method: "GET", + credentials: "include", + headers +}; + +const request = new Request("http://localhost/api/user", settings); -$.ajax(settings).done(function (response) { - console.log(response); -}); +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); ``` > Example response: @@ -56,12 +61,13 @@ $.ajax(settings).done(function (response) { ``` ### HTTP Request -`GET api/user` +`GET api/user` + ## Show the form for creating a new resource. > Example request: @@ -72,19 +78,20 @@ curl -X GET -G "http://localhost/api/user/create" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/user/create", - "method": "GET", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); + +const settings = { + method: "GET", + credentials: "include", + headers +}; + +const request = new Request("http://localhost/api/user/create", settings); -$.ajax(settings).done(function (response) { - console.log(response); -}); +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); ``` > Example response: @@ -96,12 +103,13 @@ $.ajax(settings).done(function (response) { ``` ### HTTP Request -`GET api/user/create` +`GET api/user/create` + ## Store a newly created resource in storage. > Example request: @@ -112,29 +120,30 @@ curl -X POST "http://localhost/api/user" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/user", - "method": "POST", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); -$.ajax(settings).done(function (response) { - console.log(response); -}); -``` +const settings = { + method: "POST", + credentials: "include", + headers +}; + +const request = new Request("http://localhost/api/user/create", settings); +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); +``` ### HTTP Request -`POST api/user` +`POST api/user` + ## Display the specified resource. > Example request: @@ -145,19 +154,20 @@ curl -X GET -G "http://localhost/api/user/{user}" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/user/{user}", - "method": "GET", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); + +const settings = { + method: "GET", + credentials: "include", + headers +}; -$.ajax(settings).done(function (response) { - console.log(response); -}); +const request = new Request("http://localhost/api/user/{user}", settings); + +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); ``` > Example response: @@ -169,12 +179,13 @@ $.ajax(settings).done(function (response) { ``` ### HTTP Request -`GET api/user/{user}` +`GET api/user/{user}` + ## Show the form for editing the specified resource. > Example request: @@ -185,19 +196,20 @@ curl -X GET -G "http://localhost/api/user/{user}/edit" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/user/{user}/edit", - "method": "GET", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); + +const settings = { + method: "GET", + credentials: "include", + headers +}; + +const request = new Request("http://localhost/api/user/{user}/edit", settings); -$.ajax(settings).done(function (response) { - console.log(response); -}); +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); ``` > Example response: @@ -209,12 +221,13 @@ $.ajax(settings).done(function (response) { ``` ### HTTP Request -`GET api/user/{user}/edit` +`GET api/user/{user}/edit` + ## Update the specified resource in storage. > Example request: @@ -225,31 +238,32 @@ curl -X PUT "http://localhost/api/user/{user}" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/user/{user}", - "method": "PUT", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); -$.ajax(settings).done(function (response) { - console.log(response); -}); -``` +const settings = { + method: "PUT", + credentials: "include", + headers +}; +const request = new Request("http://localhost/api/user/{user}", settings); + +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); +``` ### HTTP Request + `PUT api/user/{user}` `PATCH api/user/{user}` - + ## Remove the specified resource from storage. > Example request: @@ -260,26 +274,24 @@ curl -X DELETE "http://localhost/api/user/{user}" \ ``` ```javascript -var settings = { - "async": true, - "crossDomain": true, - "url": "http://localhost/api/user/{user}", - "method": "DELETE", - "headers": { - "accept": "application/json" - } -} +const headers = new Headers({ Accept: "application/json" }); -$.ajax(settings).done(function (response) { - console.log(response); -}); -``` +const settings = { + method: "DELETE", + credentials: "include", + headers +}; +const request = new Request("http://localhost/api/user/{user}", settings); + +fetch(request) + .then(response => response.json()) + .then(json => console.log(json)) + .catch(error => console.error(error)); +``` ### HTTP Request -`DELETE api/user/{user}` +`DELETE api/user/{user}` - -