Skip to content

Commit

Permalink
Add PHP & Python example implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dr5hn committed Oct 10, 2021
1 parent f5c3388 commit 6d4f7f7
Show file tree
Hide file tree
Showing 7 changed files with 378 additions and 26 deletions.
61 changes: 56 additions & 5 deletions docs/api/all-countries.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ title: Get a list of Countries
sidebar_label: All Countries
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

export const Highlight = ({children, color}) => (
<span
style={{
Expand All @@ -27,13 +30,16 @@ This api use API KEY as an authentication method.
No parameters

## Response
| Code | Description |
| ---- | ----------- |
| 200 | Return a list of countries |
| 401 | Unauthorized. |
| Code | Description |
| ---- | -------------------------- |
| 200 | Return a list of countries |
| 401 | Unauthorized. |

## Example Usage
```jsx title="countries-states-cities.js"
<Tabs>
<TabItem value="js" label="Javascript" default>

```jsx title="countries-states-cities.js"
var headers = new Headers();
headers.append("X-CSCAPI-KEY", "API_KEY");

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

</TabItem>

<TabItem value="php" label="PHP">

```php title="countries-states-cities.php"
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.countrystatecity.in/v1/countries',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'X-CSCAPI-KEY: API_KEY'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

</TabItem>

<TabItem value="py" label="Python">

```py title="countries-states-cities.py"
import requests

url = "https://api.countrystatecity.in/v1/countries"

headers = {
'X-CSCAPI-KEY': 'API_KEY'
}

response = requests.request("GET", url, headers=headers)

print(response.text)
```

</TabItem>
</Tabs>


## Example Success Response
```json
[
Expand Down
52 changes: 51 additions & 1 deletion docs/api/all-states.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ title: Get a list of States
sidebar_label: All States
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

export const Highlight = ({children, color}) => (
<span
style={{
Expand Down Expand Up @@ -33,7 +36,10 @@ No parameters
| 401 | Unauthorized. |

## Example Usage
```jsx title="countries-states-cities.js"
<Tabs>
<TabItem value="js" label="Javascript" default>

```jsx title="countries-states-cities.js"
var headers = new Headers();
headers.append("X-CSCAPI-KEY", "API_KEY");

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

</TabItem>

<TabItem value="php" label="PHP">

```php title="countries-states-cities.php"
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.countrystatecity.in/v1/states',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'X-CSCAPI-KEY: API_KEY'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

</TabItem>

<TabItem value="py" label="Python">

```py title="countries-states-cities.py"
import requests

url = "https://api.countrystatecity.in/v1/states"

headers = {
'X-CSCAPI-KEY': 'API_KEY'
}

response = requests.request("GET", url, headers=headers)

print(response.text)
```

</TabItem>
</Tabs>

## Example Success Response
```json
[
Expand Down
58 changes: 54 additions & 4 deletions docs/api/cities-by-country.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ title: Get a list of Cities within country
sidebar_label: Cities By Country
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

export const Highlight = ({children, color}) => (
<span
style={{
Expand Down Expand Up @@ -36,14 +39,17 @@ This api use API KEY as an authentication method.
| 404 | Not Found. |

## Example Usage
```jsx title="countries-states-cities.js"
<Tabs>
<TabItem value="js" label="Javascript" default>

```jsx title="countries-states-cities.js"
var headers = new Headers();
headers.append("X-CSCAPI-KEY", "API_KEY");

var requestOptions = {
method: 'GET',
headers: headers,
redirect: 'follow'
method: 'GET',
headers: headers,
redirect: 'follow'
};

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

</TabItem>

<TabItem value="php" label="PHP">

```php title="countries-states-cities.php"
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.countrystatecity.in/v1/countries/IN/cities',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'X-CSCAPI-KEY: API_KEY'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

</TabItem>

<TabItem value="py" label="Python">

```py title="countries-states-cities.py"
import requests

url = "https://api.countrystatecity.in/v1/countries/IN/cities"

headers = {
'X-CSCAPI-KEY': 'API_KEY'
}

response = requests.request("GET", url, headers=headers)

print(response.text)
```

</TabItem>
</Tabs>

## Example Success Response
```json
[
Expand Down
59 changes: 55 additions & 4 deletions docs/api/cities-by-state-country.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ title: Get the list of cities in a state
sidebar_label: Cities By State & Country
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

export const Highlight = ({children, color}) => (
<span
style={{
Expand Down Expand Up @@ -37,14 +40,17 @@ This api use API KEY as an authentication method.
| 404 | Not Found. |

## Example Usage
```jsx title="countries-states-cities.js"
<Tabs>
<TabItem value="js" label="Javascript" default>

```jsx title="countries-states-cities.js"
var headers = new Headers();
headers.append("X-CSCAPI-KEY", "API_KEY");

var requestOptions = {
method: 'GET',
headers: headers,
redirect: 'follow'
method: 'GET',
headers: headers,
redirect: 'follow'
};

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

</TabItem>

<TabItem value="php" label="PHP">

```php title="countries-states-cities.php"
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.countrystatecity.in/v1/countries/IN/states/MH/cities',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'X-CSCAPI-KEY: API_KEY'
),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

</TabItem>

<TabItem value="py" label="Python">

```py title="countries-states-cities.py"
import requests

url = "https://api.countrystatecity.in/v1/countries/IN/states/MH/cities"

headers = {
'X-CSCAPI-KEY': 'API_KEY'
}

response = requests.request("GET", url, headers=headers)

print(response.text)
```

</TabItem>
</Tabs>


## Example Success Response
```json
[
Expand Down
Loading

0 comments on commit 6d4f7f7

Please sign in to comment.