-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
367 lines (349 loc) · 13.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>World-Locations-API</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
background-color: #f4f4f4;
}
.container {
width: 80%;
margin: auto;
overflow: hidden;
padding: 20px;
background: #fff;
margin-top: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1, h2, h3, h4, h5, h6 {
color: #333;
}
pre {
background: #333;
color: #fff;
padding: 10px;
border-radius: 5px;
overflow-x: auto;
}
code {
background: #f4f4f4;
padding: 2px 5px;
border-radius: 3px;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>World-Locations-API</h1>
<p>Welcome to the World-Locations-API! This API provides information about continents, countries, states, and cities around the world. It is built using Node.js, Express, and PostgreSQL.</p>
<h2>Table of Contents</h2>
<ul>
<li><a href="#getting-started">Getting Started</a></li>
<li><a href="#setting-up-the-database">Setting Up the Database</a>
<ul>
<li><a href="#creating-the-database">Creating the Database</a></li>
<li><a href="#executing-datasql">Executing `data.sql`</a></li>
</ul>
</li>
<li><a href="#endpoints">Endpoints</a>
<ul>
<li><a href="#getall">Get All Locations</a></li>
<li><a href="#getcontinents">Get Continents</a></li>
<li><a href="#getcontinentidcountries">Get Countries by Continent</a></li>
<li><a href="#getcountryid">Get Country by Code</a></li>
<li><a href="#getcountrycapital">Get Country Capital</a></li>
<li><a href="#getcountryidstates">Get States by Country</a></li>
<li><a href="#getstateidcities">Get Cities by State</a></li>
<li><a href="#startswith">Get Locations starting with</a></li>
<li><a href="#endswith">Get Locations ending with</a></li>
<li><a href="#contains">Get Locations containing</a></li>
<li><a href="#postlocation">Validate Location</a></li>
</ul>
</li>
</ul>
<h2 id="getting-started">Getting Started</h2>
<p>Follow these instructions to set up and run the WorldData API on your local machine.</p>
<ol>
<li>Clone the repository:
<pre><code>git clone https://github.com/TarushGupta23/World-Locations-API
cd World-Locations-API</code></pre>
</li>
<li>Install dependencies:
<pre><code>npm install</code></pre>
</li>
<li>Run the API:
<pre><code>node index.js</code></pre>
</li>
</ol>
<p>The API will be running at <code>http://localhost:3080</code>. You can now make requests to the various endpoints.</p>
<h2 id="setting-up-the-database">Setting Up the Database</h2>
<p>Follow these steps to set up the PostgreSQL database for the WorldData API.</p>
<h3 id="creating-the-database">Creating the Database</h3>
<ol>
<li>Open pgAdmin and connect to your PostgreSQL server.</li>
<li>Create a new database named <code>WorldData</code>.</li>
<li>Update the <code>index.js</code> file with your PG-Admin password.</li>
</ol>
<h3 id="executing-datasql">Executing `data.sql`</h3>
<p>The <code>data.sql</code> file contains SQL commands to populate the database with initial data.</p>
<ol>
<li>In pgAdmin, open a query tool for the <code>WorldData</code> database.</li>
<li>Copy the contents of the <code>data.sql</code> file and paste them into the query tool.</li>
<li>Execute the script to create tables and insert initial data.</li>
</ol>
<p><strong>Note:</strong> Ensure that the <code>pg_password</code> in the <code>index.js</code> file matches your PG-Admin password.</p>
<p>The database is now set up with initial data.</p>
<h2 id="endpoints">Endpoints</h2>
<h3 id="getall">Get All Locations</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/all</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get a list of all locations, including continents, countries, states, and cities.
<pre><code>[
{
"continent_code": "AS",
"name": "Asia",
"countries": [
{
"country_code": "IN",
"continent_code": "AS",
"name": "India",
"capital": "New Delhi",
"states": [
{
"state_id": "UP",
"country_code": "IN",
"name": "Uttar Pradesh",
"cities": [
{
"city_id": "LUK",
"state_id": "UP",
"name": "Lucknow"
}
]
}
]
}
]
},
{
"continent_code": "EU",
"name": "Europe",
"countries": [
{
"country_code": "FR",
"continent_code": "EU",
"name": "France",
"capital": "Paris",
"states": [
{
"state_id": "IDF",
"country_code": "FR",
"name": "Île-de-France",
"cities": [
{
"city_id": "PAR",
"state_id": "IDF",
"name": "Paris"
}
]
}
]
}
]
},
{
"continent_code": "NA",
"name": "North America",
"countries": [
{
"country_code": "US",
"continent_code": "NA",
"name": "United States",
"capital": "Washington, D.C.",
"states": [
{
"state_id": "CA",
"country_code": "US",
"name": "California",
"cities": [
{
"city_id": "SFO",
"state_id": "CA",
"name": "San Francisco"
}
]
}
]
}
]
},
{
"continent_code": "SA",
"name": "South America",
"countries": [
{
"country_code": "BR",
"continent_code": "SA",
"name": "Brazil",
"capital": "Brasília",
"states": [
{
"state_id": "SP",
"country_code": "BR",
"name": "São Paulo",
"cities": [
{
"city_id": "SAO",
"state_id": "SP",
"name": "São Paulo"
}
]
}
]
}
]
}
]</code></pre>
</li>
</ul>
<h3 id="getcontinents">Get Continents</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/continents</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get a list of all continents.
<pre><code>[
{
"continent_code": "AS",
"name": "Asia"
},
{
"continent_code": "EU",
"name": "Europe"
},
{
"continent_code": "NA",
"name": "North America"
},
{
"continent_code": "SA",
"name": "South America"
}
]</code></pre>
</li>
</ul>
<h3 id="getcontinentidcountries">Get Countries by Continent</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/continent/:id/countries</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get all countries on a specific continent. Replace <code>:id</code> with the continent code.
<pre><code>[
{
"country_code": "IN",
"continent_code": "AS",
"name": "India",
"capital": "New Delhi"
}
]</code></pre>
</li>
</ul>
<h3 id="getcountryid">Get Country by Code</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/country/:id</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get details of a country by its country code. Replace <code>:id</code> with the country code.
<pre><code>{
"country_code": "IN",
"continent_code": "AS",
"name": "India",
"capital": "New Delhi"
}</code></pre>
</li>
</ul>
<h3 id="getcountrycapital">Get Capital of a Country</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/country/:id/capital</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get capital city of a country by its country code. Replace <code>:id</code> with country code
<pre><code>{
"capital": "New Delhi"
}</code></pre>
</li>
</ul>
<h3 id="getcountryidstates">Get States by Country</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/country/:id/states</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get states inside a specific country. Replace <code>:id</code> with the country code.
<pre><code>[
{
"state_id": "UP",
"country_code": "IN",
"name": "Uttar Pradesh"
}
]</code></pre>
</li>
</ul>
<h3 id="getstateidcities">Get Cities by State</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/state/:id/cities</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get cities inside a specific state. Replace <code>:id</code> with the state ID.
<pre><code>[
{
"city_id": "LUK",
"state_id": "UP",
"name": "Lucknow"
}
]</code></pre>
</li>
</ul>
<h3 id="startswith">Get Locations Starting with</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/starts-with/:char</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get all locations which starts with given character sequence. replace <code>:char</code> with character sequence, use <strong>_</strong> to simply get list of all locations' name
</li>
</ul>
<h3 id="endswith">Get Locations Ending with</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/ends-with/:char</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get all locations which ends with given character sequence. replace <code>:char</code> with character sequence, use <strong>_</strong> to simply get list of all locations' name
</li>
</ul>
<h3 id="contains">Get Locations Containing</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/contains/:char</code></li>
<li><strong>Method:</strong> <code>GET</code></li>
<li><strong>Description:</strong> Get all locations which contains given character sequence. replace <code>:char</code> with character sequence, use <strong>_</strong> to simply get list of all locations' name
</li>
</ul>
<h3 id="postlocation">Validate Location</h3>
<ul>
<li><strong>Endpoint:</strong> <code>/location/:loc</code></li>
<li><strong>Method:</strong> <code>POST</code></li>
<li><strong>Description:</strong> Validate a location by providing the location name in the request body. Returns the location ID and type (continent, country, state, or city).
<pre><code>{
"id": "IN",
"type": "country"
}</code></pre>
</li>
</ul>
<p>Feel free to explore and integrate the WorldData API into your applications! If you have any questions or issues, please open an <a href="https://github.com/TarushGupta23/World-Locations-API/issues">issue</a>.</p>
</div>
</body>
</html>