Skip to content

Commit 16432d8

Browse files
Merge pull request #6 from IFRCGo/WN-200
Create endpoints view
2 parents 7a3d6f1 + 2a80f5c commit 16432d8

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Support\Facades\Route;
6+
7+
class RouteController extends Controller
8+
{
9+
public function index()
10+
{
11+
$routes = collect(Route::getRoutes())->filter(function ($route) {
12+
return strpos($route->getActionName(), 'App\Http\Controllers') !== false;
13+
})->map(function ($route) {
14+
return [
15+
'url' => $route->uri(),
16+
'name' => $route->getName(),
17+
'action' => $route->getActionName(),
18+
'method' => $route->methods()[0], // Get the first HTTP method for the route
19+
'middleware' => $route->middleware(),
20+
];
21+
});
22+
23+
return view('endpoints', [
24+
'routeData' => $routes,
25+
]);
26+
}
27+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>API Endpoints</title>
7+
<style>
8+
/* General styling for dark theme */
9+
body {
10+
background-color: #121212;
11+
color: #e0e0e0;
12+
font-family: Arial, sans-serif;
13+
margin: 0;
14+
padding: 0;
15+
}
16+
.container {
17+
max-width: 800px;
18+
margin: 0 auto;
19+
padding: 20px;
20+
}
21+
22+
/* Search box styling */
23+
.search-container {
24+
margin-bottom: 20px;
25+
}
26+
.search-input {
27+
width: 100%;
28+
padding: 10px;
29+
font-size: 16px;
30+
background-color: #1e1e1e;
31+
color: #e0e0e0;
32+
border: 1px solid #333;
33+
border-radius: 4px;
34+
}
35+
36+
/* Card styling */
37+
.card {
38+
background-color: #1e1e1e;
39+
border: 1px solid #333;
40+
border-radius: 8px;
41+
padding: 20px;
42+
}
43+
.card-header {
44+
font-size: 22px;
45+
font-weight: bold;
46+
color: #ffffff;
47+
margin-bottom: 15px;
48+
}
49+
50+
/* Endpoint list styling */
51+
.endpoint-list {
52+
list-style-type: none;
53+
padding: 0;
54+
margin: 0;
55+
}
56+
.endpoint-item {
57+
border-bottom: 1px solid #333;
58+
padding: 10px 0;
59+
}
60+
.endpoint-info {
61+
display: flex;
62+
align-items: center;
63+
margin-bottom: 5px;
64+
}
65+
66+
/* Method badge styles */
67+
.endpoint-method {
68+
padding: 6px 10px;
69+
border-radius: 4px;
70+
font-weight: bold;
71+
color: #ffffff;
72+
margin-right: 10px;
73+
text-transform: uppercase;
74+
}
75+
.get { background-color: #4caf50; }
76+
.post { background-color: #2196f3; }
77+
.put { background-color: #ff9800; }
78+
.delete { background-color: #f44336; }
79+
80+
81+
/* URL and description styles */
82+
.endpoint-url {
83+
font-weight: bold;
84+
color: #e0e0e0;
85+
}
86+
.endpoint-description {
87+
color: #b0b0b0;
88+
}
89+
</style>
90+
</head>
91+
<body>
92+
<div class="container">
93+
<div class="search-container">
94+
<input type="text" class="search-input" placeholder="Search endpoints..." />
95+
</div>
96+
97+
<div class="card">
98+
<div class="card-header">API Endpoints</div>
99+
<ul class="endpoint-list">
100+
@foreach ($routeData as $route)
101+
<li class="endpoint-item">
102+
<div class="endpoint-info">
103+
<div class="endpoint-method {{ strtolower($route['method']) }}">{{ $route['method'] }}</div>
104+
<div class="endpoint-url">{{ $route['url'] }}</div>
105+
</div>
106+
<div class="endpoint-description">{{ $route['name'] }} - {{ $route['action'] }}</div>
107+
</li>
108+
@endforeach
109+
</ul>
110+
</div>
111+
</div>
112+
113+
<script>
114+
const searchInput = document.querySelector('.search-input');
115+
const endpointItems = document.querySelectorAll('.endpoint-item');
116+
117+
searchInput.addEventListener('input', () => {
118+
const searchTerm = searchInput.value.toLowerCase();
119+
endpointItems.forEach(item => {
120+
const url = item.querySelector('.endpoint-url').textContent.toLowerCase();
121+
const description = item.querySelector('.endpoint-description').textContent.toLowerCase();
122+
if (url.includes(searchTerm) || description.includes(searchTerm)) {
123+
item.style.display = 'block';
124+
} else {
125+
item.style.display = 'none';
126+
}
127+
});
128+
});
129+
</script>
130+
</body>
131+
</html>

routes/web.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@
1616
Route::get('/', function () {
1717
return redirect()->to('https://whatnow.preparecenter.org');
1818
});
19+
// API documentation
20+
Route::get('/endpoints', [\App\Http\Controllers\RouteController::class, 'index'])
21+
->name('endpoints.index'); // Displays list of available API endpoints with documentation

0 commit comments

Comments
 (0)