From 708d64b13133d86d2e0a096818138c78c7b10537 Mon Sep 17 00:00:00 2001 From: Arash Khazaei <0xclay@gmail.com> Date: Mon, 17 Sep 2018 00:59:44 +0430 Subject: [PATCH 1/3] Update javascript request example to fetch api --- src/resources/views/partials/route.blade.php | 26 +++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) 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'])) From c5d36065445b9613eabe1a6a9df1d8dd02809a65 Mon Sep 17 00:00:00 2001 From: Arash Khazaei <0xclay@gmail.com> Date: Tue, 18 Sep 2018 23:56:36 +0430 Subject: [PATCH 2/3] Update test fixtures to fetch Api --- tests/Fixtures/index.md | 65 +++++----- tests/Fixtures/resource_index.md | 198 ++++++++++++++++--------------- 2 files changed, 140 insertions(+), 123 deletions(-) diff --git a/tests/Fixtures/index.md b/tests/Fixtures/index.md index 14b0648e..d9844fd7 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'}) + +const settings = { + method: "GET" + credentials: 'include' + headers, } -$.ajax(settings).done(function (response) { - console.log(response); -}); +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, } -$.ajax(settings).done(function (response) { - console.log(response); -}); +const request = new Request("http://localhost/api/fetch", settings) + +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..8d4a7f4d 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, } -$.ajax(settings).done(function (response) { - console.log(response); -}); +const request = new Request("http://localhost/api/user", settings) + +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, } -$.ajax(settings).done(function (response) { - console.log(response); -}); +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)) ``` > 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'}) + +const settings = { + method: "POST" + credentials: 'include' + headers, } -$.ajax(settings).done(function (response) { - console.log(response); -}); -``` +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, } -$.ajax(settings).done(function (response) { - console.log(response); -}); +const request = new Request("http://localhost/api/user/{user}/edit", settings) + +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'}) + +const settings = { + method: "PUT" + 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)) +``` ### 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'}) + +const settings = { + method: "DELETE" + 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)) +``` ### HTTP Request -`DELETE api/user/{user}` +`DELETE api/user/{user}` - - From baf1bbce1fa1e527befab2b101c4377559f24d1d Mon Sep 17 00:00:00 2001 From: Arash Khazaei <0xclay@gmail.com> Date: Wed, 19 Sep 2018 00:04:27 +0430 Subject: [PATCH 3/3] Fix add trailing comma to objects --- tests/Fixtures/index.md | 28 ++++----- tests/Fixtures/resource_index.md | 98 ++++++++++++++++---------------- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/tests/Fixtures/index.md b/tests/Fixtures/index.md index d9844fd7..037562a8 100644 --- a/tests/Fixtures/index.md +++ b/tests/Fixtures/index.md @@ -39,20 +39,20 @@ curl -X GET -G "http://localhost/api/test" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "GET" - credentials: 'include' - headers, -} + method: "GET", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/test", settings) +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)) + .catch(error => console.error(error)); ``` > Example response: @@ -79,20 +79,20 @@ curl -X GET -G "http://localhost/api/fetch" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "GET" - credentials: 'include' - headers, -} + method: "GET", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/fetch", settings) +const request = new Request("http://localhost/api/fetch", settings); fetch(request) .then(response => response.json()) .then(json => console.log(json)) - .catch(error => console.error(error)) + .catch(error => console.error(error)); ``` > Example response: diff --git a/tests/Fixtures/resource_index.md b/tests/Fixtures/resource_index.md index 8d4a7f4d..7c5b894b 100644 --- a/tests/Fixtures/resource_index.md +++ b/tests/Fixtures/resource_index.md @@ -36,20 +36,20 @@ curl -X GET -G "http://localhost/api/user" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "GET" - credentials: 'include' - headers, -} + method: "GET", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/user", settings) +const request = new Request("http://localhost/api/user", settings); fetch(request) .then(response => response.json()) .then(json => console.log(json)) - .catch(error => console.error(error)) + .catch(error => console.error(error)); ``` > Example response: @@ -78,20 +78,20 @@ curl -X GET -G "http://localhost/api/user/create" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "GET" - credentials: 'include' - headers, -} + method: "GET", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/user/create", settings) +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)) + .catch(error => console.error(error)); ``` > Example response: @@ -120,20 +120,20 @@ curl -X POST "http://localhost/api/user" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "POST" - credentials: 'include' - headers, -} + method: "POST", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/user/create", settings) +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)) + .catch(error => console.error(error)); ``` ### HTTP Request @@ -154,20 +154,20 @@ curl -X GET -G "http://localhost/api/user/{user}" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "GET" - credentials: 'include' - headers, -} + method: "GET", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/user/{user}", settings) +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)) + .catch(error => console.error(error)); ``` > Example response: @@ -196,20 +196,20 @@ curl -X GET -G "http://localhost/api/user/{user}/edit" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "GET" - credentials: 'include' - headers, -} + method: "GET", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/user/{user}/edit", settings) +const request = new Request("http://localhost/api/user/{user}/edit", settings); fetch(request) .then(response => response.json()) .then(json => console.log(json)) - .catch(error => console.error(error)) + .catch(error => console.error(error)); ``` > Example response: @@ -238,20 +238,20 @@ curl -X PUT "http://localhost/api/user/{user}" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "PUT" - credentials: 'include' - headers, -} + method: "PUT", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/user/{user}", settings) +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)) + .catch(error => console.error(error)); ``` ### HTTP Request @@ -274,20 +274,20 @@ curl -X DELETE "http://localhost/api/user/{user}" \ ``` ```javascript -const headers = new Headers({'Accept': 'application/json'}) +const headers = new Headers({ Accept: "application/json" }); const settings = { - method: "DELETE" - credentials: 'include' - headers, -} + method: "DELETE", + credentials: "include", + headers +}; -const request = new Request("http://localhost/api/user/{user}", settings) +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)) + .catch(error => console.error(error)); ``` ### HTTP Request