Skip to content

Commit 6d4f7f7

Browse files
committed
Add PHP & Python example implementation
1 parent f5c3388 commit 6d4f7f7

7 files changed

+378
-26
lines changed

Diff for: docs/api/all-countries.md

+56-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Get a list of Countries
44
sidebar_label: All Countries
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
export const Highlight = ({children, color}) => (
811
<span
912
style={{
@@ -27,13 +30,16 @@ This api use API KEY as an authentication method.
2730
No parameters
2831

2932
## Response
30-
| Code | Description |
31-
| ---- | ----------- |
32-
| 200 | Return a list of countries |
33-
| 401 | Unauthorized. |
33+
| Code | Description |
34+
| ---- | -------------------------- |
35+
| 200 | Return a list of countries |
36+
| 401 | Unauthorized. |
3437

3538
## Example Usage
36-
```jsx title="countries-states-cities.js"
39+
<Tabs>
40+
<TabItem value="js" label="Javascript" default>
41+
42+
```jsx title="countries-states-cities.js"
3743
var headers = new Headers();
3844
headers.append("X-CSCAPI-KEY", "API_KEY");
3945

@@ -49,6 +55,51 @@ fetch("https://api.countrystatecity.in/v1/countries", requestOptions)
4955
.catch(error => console.log('error', error));
5056
```
5157

58+
</TabItem>
59+
60+
<TabItem value="php" label="PHP">
61+
62+
```php title="countries-states-cities.php"
63+
<?php
64+
65+
$curl = curl_init();
66+
67+
curl_setopt_array($curl, array(
68+
CURLOPT_URL => 'https://api.countrystatecity.in/v1/countries',
69+
CURLOPT_RETURNTRANSFER => true,
70+
CURLOPT_HTTPHEADER => array(
71+
'X-CSCAPI-KEY: API_KEY'
72+
),
73+
));
74+
75+
$response = curl_exec($curl);
76+
77+
curl_close($curl);
78+
echo $response;
79+
```
80+
81+
</TabItem>
82+
83+
<TabItem value="py" label="Python">
84+
85+
```py title="countries-states-cities.py"
86+
import requests
87+
88+
url = "https://api.countrystatecity.in/v1/countries"
89+
90+
headers = {
91+
'X-CSCAPI-KEY': 'API_KEY'
92+
}
93+
94+
response = requests.request("GET", url, headers=headers)
95+
96+
print(response.text)
97+
```
98+
99+
</TabItem>
100+
</Tabs>
101+
102+
52103
## Example Success Response
53104
```json
54105
[

Diff for: docs/api/all-states.md

+51-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Get a list of States
44
sidebar_label: All States
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
export const Highlight = ({children, color}) => (
811
<span
912
style={{
@@ -33,7 +36,10 @@ No parameters
3336
| 401 | Unauthorized. |
3437

3538
## Example Usage
36-
```jsx title="countries-states-cities.js"
39+
<Tabs>
40+
<TabItem value="js" label="Javascript" default>
41+
42+
```jsx title="countries-states-cities.js"
3743
var headers = new Headers();
3844
headers.append("X-CSCAPI-KEY", "API_KEY");
3945

@@ -49,6 +55,50 @@ fetch("https://api.countrystatecity.in/v1/states", requestOptions)
4955
.catch(error => console.log('error', error));
5056
```
5157

58+
</TabItem>
59+
60+
<TabItem value="php" label="PHP">
61+
62+
```php title="countries-states-cities.php"
63+
<?php
64+
65+
$curl = curl_init();
66+
67+
curl_setopt_array($curl, array(
68+
CURLOPT_URL => 'https://api.countrystatecity.in/v1/states',
69+
CURLOPT_RETURNTRANSFER => true,
70+
CURLOPT_HTTPHEADER => array(
71+
'X-CSCAPI-KEY: API_KEY'
72+
),
73+
));
74+
75+
$response = curl_exec($curl);
76+
77+
curl_close($curl);
78+
echo $response;
79+
```
80+
81+
</TabItem>
82+
83+
<TabItem value="py" label="Python">
84+
85+
```py title="countries-states-cities.py"
86+
import requests
87+
88+
url = "https://api.countrystatecity.in/v1/states"
89+
90+
headers = {
91+
'X-CSCAPI-KEY': 'API_KEY'
92+
}
93+
94+
response = requests.request("GET", url, headers=headers)
95+
96+
print(response.text)
97+
```
98+
99+
</TabItem>
100+
</Tabs>
101+
52102
## Example Success Response
53103
```json
54104
[

Diff for: docs/api/cities-by-country.md

+54-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Get a list of Cities within country
44
sidebar_label: Cities By Country
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
export const Highlight = ({children, color}) => (
811
<span
912
style={{
@@ -36,14 +39,17 @@ This api use API KEY as an authentication method.
3639
| 404 | Not Found. |
3740

3841
## Example Usage
39-
```jsx title="countries-states-cities.js"
42+
<Tabs>
43+
<TabItem value="js" label="Javascript" default>
44+
45+
```jsx title="countries-states-cities.js"
4046
var headers = new Headers();
4147
headers.append("X-CSCAPI-KEY", "API_KEY");
4248

4349
var requestOptions = {
44-
method: 'GET',
45-
headers: headers,
46-
redirect: 'follow'
50+
method: 'GET',
51+
headers: headers,
52+
redirect: 'follow'
4753
};
4854

4955
fetch("https://api.countrystatecity.in/v1/countries/IN/cities", requestOptions)
@@ -52,6 +58,50 @@ fetch("https://api.countrystatecity.in/v1/countries/IN/cities", requestOptions)
5258
.catch(error => console.log('error', error));
5359
```
5460

61+
</TabItem>
62+
63+
<TabItem value="php" label="PHP">
64+
65+
```php title="countries-states-cities.php"
66+
<?php
67+
68+
$curl = curl_init();
69+
70+
curl_setopt_array($curl, array(
71+
CURLOPT_URL => 'https://api.countrystatecity.in/v1/countries/IN/cities',
72+
CURLOPT_RETURNTRANSFER => true,
73+
CURLOPT_HTTPHEADER => array(
74+
'X-CSCAPI-KEY: API_KEY'
75+
),
76+
));
77+
78+
$response = curl_exec($curl);
79+
80+
curl_close($curl);
81+
echo $response;
82+
```
83+
84+
</TabItem>
85+
86+
<TabItem value="py" label="Python">
87+
88+
```py title="countries-states-cities.py"
89+
import requests
90+
91+
url = "https://api.countrystatecity.in/v1/countries/IN/cities"
92+
93+
headers = {
94+
'X-CSCAPI-KEY': 'API_KEY'
95+
}
96+
97+
response = requests.request("GET", url, headers=headers)
98+
99+
print(response.text)
100+
```
101+
102+
</TabItem>
103+
</Tabs>
104+
55105
## Example Success Response
56106
```json
57107
[

Diff for: docs/api/cities-by-state-country.md

+55-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ title: Get the list of cities in a state
44
sidebar_label: Cities By State & Country
55
---
66

7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
710
export const Highlight = ({children, color}) => (
811
<span
912
style={{
@@ -37,14 +40,17 @@ This api use API KEY as an authentication method.
3740
| 404 | Not Found. |
3841

3942
## Example Usage
40-
```jsx title="countries-states-cities.js"
43+
<Tabs>
44+
<TabItem value="js" label="Javascript" default>
45+
46+
```jsx title="countries-states-cities.js"
4147
var headers = new Headers();
4248
headers.append("X-CSCAPI-KEY", "API_KEY");
4349

4450
var requestOptions = {
45-
method: 'GET',
46-
headers: headers,
47-
redirect: 'follow'
51+
method: 'GET',
52+
headers: headers,
53+
redirect: 'follow'
4854
};
4955

5056
fetch("https://api.countrystatecity.in/v1/countries/IN/states/MH/cities", requestOptions)
@@ -53,6 +59,51 @@ fetch("https://api.countrystatecity.in/v1/countries/IN/states/MH/cities", reques
5359
.catch(error => console.log('error', error));
5460
```
5561

62+
</TabItem>
63+
64+
<TabItem value="php" label="PHP">
65+
66+
```php title="countries-states-cities.php"
67+
<?php
68+
69+
$curl = curl_init();
70+
71+
curl_setopt_array($curl, array(
72+
CURLOPT_URL => 'https://api.countrystatecity.in/v1/countries/IN/states/MH/cities',
73+
CURLOPT_RETURNTRANSFER => true,
74+
CURLOPT_HTTPHEADER => array(
75+
'X-CSCAPI-KEY: API_KEY'
76+
),
77+
));
78+
79+
$response = curl_exec($curl);
80+
81+
curl_close($curl);
82+
echo $response;
83+
```
84+
85+
</TabItem>
86+
87+
<TabItem value="py" label="Python">
88+
89+
```py title="countries-states-cities.py"
90+
import requests
91+
92+
url = "https://api.countrystatecity.in/v1/countries/IN/states/MH/cities"
93+
94+
headers = {
95+
'X-CSCAPI-KEY': 'API_KEY'
96+
}
97+
98+
response = requests.request("GET", url, headers=headers)
99+
100+
print(response.text)
101+
```
102+
103+
</TabItem>
104+
</Tabs>
105+
106+
56107
## Example Success Response
57108
```json
58109
[

0 commit comments

Comments
 (0)