Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 36 additions & 14 deletions resources/views/partials/route.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,46 @@
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "{{ rtrim(config('app.docs_url') ?: config('app.url'), '/') }}/{{ ltrim($route['uri'], '/') }}",
"method": "{{$route['methods'][0]}}",
@if(count($route['bodyParameters']))
"data": {!! str_replace("\n}","\n }", str_replace(' ',' ',json_encode(array_combine(array_keys($route['bodyParameters']), array_map(function($param){ return $param['value']; },$route['bodyParameters'])), JSON_PRETTY_PRINT))) !!},
@endif
"headers": {
const url = new URL("{{ rtrim(config('app.docs_url') ?: config('app.url'), '/') }}/{{ ltrim($route['uri'], '/') }}");
@if(count($route['queryParameters']))

let params = {
@foreach($route['queryParameters'] as $attribute => $parameter)
"{{ $attribute }}": "{{ $parameter['value'] }}",
@endforeach
};
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
@endif

let headers = {
@foreach($route['headers'] as $header => $value)
"{{$header}}": "{{$value}}",
"{{$header}}": "{{$value}}",
@endforeach
}
@if(!array_key_exists('Accept', $route['headers']))
"Accept": "application/json",
@endif
@if(!array_key_exists('Content-Type', $route['headers']))
"Content-Type": "application/json",
@endif
}
@if(count($route['bodyParameters']))

$.ajax(settings).done(function (response) {
console.log(response);
});
let body = JSON.stringify({
@foreach($route['bodyParameters'] as $attribute => $parameter)
"{{ $attribute }}": "{{ $parameter['value'] }}",
@endforeach
})
@endif

fetch(url, {
method: "{{$route['methods'][0]}}",
headers: headers,
@if(count($route['bodyParameters']))
body: body
@endif
})
.then(response => response.json())
.then(json => console.log(json));
```

@if(in_array('GET',$route['methods']) || (isset($route['showresponse']) && $route['showresponse']))
Expand Down
24 changes: 11 additions & 13 deletions tests/Fixtures/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,19 @@ curl -X GET -G "http://localhost/api/withDescription" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/withDescription",
"method": "GET",
"headers": {
"accept": "application/json",
"Authorization": "customAuthToken",
"Custom-Header": "NotSoCustom",
}
const url = new URL("http://localhost/api/users");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "GET",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```

> Example response:
Expand Down
44 changes: 22 additions & 22 deletions tests/Fixtures/partial_resource_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ curl -X GET -G "http://localhost/api/users" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users",
"method": "GET",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "GET",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```

> Example response:
Expand Down Expand Up @@ -72,19 +72,19 @@ curl -X GET -G "http://localhost/api/users/create" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users/create",
"method": "GET",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users/create");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "GET",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```

> Example response:
Expand Down
154 changes: 77 additions & 77 deletions tests/Fixtures/resource_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ curl -X GET -G "http://localhost/api/users" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users",
"method": "GET",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "GET",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```

> Example response:
Expand Down Expand Up @@ -72,19 +72,19 @@ curl -X GET -G "http://localhost/api/users/create" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users/create",
"method": "GET",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users/create");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "GET",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```

> Example response:
Expand Down Expand Up @@ -112,19 +112,19 @@ curl -X POST "http://localhost/api/users" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users",
"method": "POST",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "POST",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```


Expand All @@ -145,19 +145,19 @@ curl -X GET -G "http://localhost/api/users/{user}" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users/{user}",
"method": "GET",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users/{user}");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "GET",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```

> Example response:
Expand Down Expand Up @@ -185,19 +185,19 @@ curl -X GET -G "http://localhost/api/users/{user}/edit" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users/{user}/edit",
"method": "GET",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users/{user}/edit");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "GET",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```

> Example response:
Expand Down Expand Up @@ -225,19 +225,19 @@ curl -X PUT "http://localhost/api/users/{user}" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users/{user}",
"method": "PUT",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users/{user}");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "PUT",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```


Expand All @@ -260,19 +260,19 @@ curl -X DELETE "http://localhost/api/users/{user}" \
```

```javascript
var settings = {
"async": true,
"crossDomain": true,
"url": "http://localhost/api/users/{user}",
"method": "DELETE",
"headers": {
"Accept": "application/json",
}
const url = new URL("http://localhost/api/users/{user}");

let headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}

$.ajax(settings).done(function (response) {
console.log(response);
});
fetch(url, {
method: "DELETE",
headers: headers,
})
.then(response => response.json())
.then(json => console.log(json));
```


Expand Down