# Script HTTP client

> **Note**
> This example can only run on [OAK POE devices](https://docs.luxonis.com/projects/hardware/en/latest/#poe-designs). You need bootloader on/above version 0.0.15. You can flash bootloader by running `python3 examples/bootloader/flash_bootloader.py`.

This example will send an [HTTP request](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) to the http://api.ipify.org
and print your public IP.

## Demo

```bash
~/depthai-python/examples/Script$ python3 script_http_client.py
Sending http GET request...
200 OK
Public IP: b'123.123.123.123'
```

## Setup

Please run the [install script](https://github.com/luxonis/depthai-python/blob/main/examples/install_requirements.py) to download
all required dependencies. Please note that this script must be ran from git context, so you have to download the
[depthai-python](https://github.com/luxonis/depthai-python) repository first and then run the script

```bash
git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py
```

For additional information, please follow the [installation guide](https://docs.luxonis.com/software/depthai/manual-install.md).

## Source code

#### Python

```python
#!/usr/bin/env python3
import depthai as dai

# Start defining a pipeline
pipeline = dai.Pipeline()

# Script node
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
script.setScript("""
    import http.client
    import time

    node.warn('Sending http GET request...')
    h1 = http.client.HTTPConnection('api.ipify.org', 80)
    h1.request("GET", "/")
    r1 = h1.getresponse()
    node.warn(f'{r1.status} {r1.reason}')
    data1 = r1.read()
    node.warn(f'Public IP: {data1}')

    node.io['end'].send(Buffer(32))
""")

xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName('end')
script.outputs['end'].link(xout.input)

# Connect to device with pipeline
with dai.Device(pipeline) as device:
    device.getOutputQueue("end").get() # Wait for the "end" msg
```

#### C++

```cpp
#include <iostream>

// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"

int main() {
    using namespace std;

    // Start defining a pipeline
    dai::Pipeline pipeline;

    // Script node
    auto script = pipeline.create<dai::node::Script>();
    script->setProcessor(dai::ProcessorType::LEON_CSS);
    script->setScript(R"(
    import http.client
    import time

    node.warn('Sending http GET request...')
    h1 = http.client.HTTPConnection('api.ipify.org', 80)
    h1.request("GET", "/")
    r1 = h1.getresponse()
    node.warn(f'{r1.status} {r1.reason}')
    data1 = r1.read()
    node.warn(f'Public IP: {data1}')

    node.io['end'].send(Buffer(32))
    )");

    // XLinkOut
    auto xout = pipeline.create<dai::node::XLinkOut>();
    xout->setStreamName("end");
    script->outputs["end"].link(xout->input);

    // Connect to device with pipeline
    dai::Device device(pipeline);
    device.getOutputQueue("end")->get<dai::Buffer>();
    return 0;
}
```

## Pipeline

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
