Skip to content

Commit 113bcad

Browse files
committed
Add API endpoint using netlify edge function 🪄
1 parent 99848b8 commit 113bcad

File tree

9 files changed

+18151
-227
lines changed

9 files changed

+18151
-227
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
app/node_modules
22
.vscode
3+
4+
# Local Netlify folder
5+
.netlify

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,98 @@ npm install
6868
npm run build
6969
```
7070

71+
## API 🚀
72+
73+
WhereRoulette provides a simple API using Netlify Edge Functions to retrieve POIs within a specified region. Mix some randomness into your apps or get details about specific locations! ✨
74+
75+
### POI Endpoint ⚡
76+
77+
```bash
78+
GET https://whereroulette.com/api
79+
```
80+
81+
#### Query Parameters 🔍
82+
83+
| Parameter | Description | Required | Default |
84+
|-----------|-------------|----------|---------|
85+
| region | OpenStreetMap region ID | Yes | - |
86+
| type | POI category (drinks, cafe, food, park, climb) | No | drinks |
87+
| id | Specific OSM node ID (e.g., "node/11967421222" or just "11967421222") | No | - |
88+
89+
#### Usage Examples 📝
90+
91+
**Random POI:**
92+
93+
```bash
94+
https://whereroulette.com/api?region=62422&type=climb
95+
```
96+
97+
**Specific POI by ID:**
98+
99+
```bash
100+
https://whereroulette.com/api?region=62422&type=climb&id=node%2F11967421222
101+
```
102+
103+
#### Response Example 💾
104+
105+
```json
106+
{
107+
"osm_node": "11967421222",
108+
"name": "Bouldergarten",
109+
"type": "climb",
110+
"emoji": "🧗",
111+
"opening_hours": "Mo-Fr 10:00-23:00, Sa,Su 10:00-22:00",
112+
"url": "https://whereroulette.com/?region=62422&type=climb&id=node%2F11967421222",
113+
"coordinates": [13.4567, 52.4890]
114+
}
115+
```
116+
117+
#### Error Responses ⚠️
118+
119+
**Missing Region:**
120+
121+
```json
122+
{
123+
"error": "Missing required parameter: region"
124+
}
125+
```
126+
127+
**Invalid Category:**
128+
129+
```json
130+
{
131+
"error": "Invalid type. Must be one of: drinks, cafe, food, park, climb"
132+
}
133+
```
134+
135+
**No POIs Found:**
136+
137+
```json
138+
{
139+
"error": "No climb found in region 62422"
140+
}
141+
```
142+
143+
**Node Not Found:**
144+
145+
```json
146+
{
147+
"error": "Node with ID node/12345678 not found"
148+
}
149+
```
150+
151+
### Technical Implementation 🛠️
152+
153+
The API is implemented as a Netlify Edge Function, which provides fast, globally distributed response times. It directly queries the Overpass API to fetch OpenStreetMap data and converts it to a simplified format optimized for POI information.
154+
155+
The configuration in `netlify.toml` maps the `/api` path to the Edge Function:
156+
157+
```toml
158+
[[edge_functions]]
159+
function = "json"
160+
path = "/api"
161+
```
162+
71163
## Deployment
72164

73165
### Frontend - GitHub Pages

0 commit comments

Comments
 (0)