# Need help / sample code snippet to implement the typescript react code to connect to elastic-search server to push data to index

**URL:** <https://discuss.elastic.co/t/need-help-sample-code-snippet-to-implement-the-typescript-react-code-to-connect-to-elastic-search-server-to-push-data-to-index/358762>\
**Category:** Kibana\
**Tags:** elastic-stack-monitoring, elastic-stack-security, elastic-stack-machine-learning, elastic-stack-alerting, ilm-index-lifecycle-management\
**Created:** [May 5, 2024, 6:29pm UTC](https://discuss.elastic.co/t/need-help-sample-code-snippet-to-implement-the-typescript-react-code-to-connect-to-elastic-search-server-to-push-data-to-index/358762 "2024-05-05T18:29:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sunil\_Jagtap](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sunil_jagtap/32/133604_2.png) [@Sunil\_Jagtap](https://discuss.elastic.co/u/Sunil_Jagtap)\
**Post date:** [May 5, 2024, 6:29pm UTC](https://discuss.elastic.co/t/need-help-sample-code-snippet-to-implement-the-typescript-react-code-to-connect-to-elastic-search-server-to-push-data-to-index/358762/1 "2024-05-05T18:29:33Z")

</div>

Need help / sample code snippet to implement the typescript react code to connect to elastic-search server to push data to index from kibana running on local, This may need to bypass proxy & SSL certificate.

**Below code snippet is working on local :**

```auto
export const TestPlug2App = ({ basename, notifications, http, navigation }: TestPlug2AppDeps) => {
  const indexName = 'test_index'; // Example index name, replace with your actual index name
  const endpoint = `http://localhost:9200/${indexName}/_doc`;

  const [formData, setFormData] = useState({
    acc_name: 'acc1',
    skill: 'xyz',
  });

  const handleSubmit = async (event: React.FormEvent) => {
    event.preventDefault();
    try {
      // Send POST request to Elasticsearch to save form data
      await http.post(endpoint, {
        body: JSON.stringify(formData),
        headers: {
          'Content-Type': 'application/json',
        },
      });

```

**I want this to work for elasticsearch sever running on remote :**

Example :

```auto
export const TestPlug2App = ({ basename, notifications, http, navigation }: TestPlug2AppDeps) => {
  const indexName = 'test_index'; // Example index name, replace with your actual index name
  const endpoint = `http://remotehost.domain.net:9200/${indexName}/_doc`;

  const [formData, setFormData] = useState({
    acc_name: 'acc1',
    skill: 'xyz',
  });

  const handleSubmit = async (event: React.FormEvent) => {
    event.preventDefault();
    try {
      // Send POST request to Elasticsearch to save form data
      await http.post(endpoint, {
        body: JSON.stringify(formData),
        headers: {
          'Content-Type': 'application/json',
                    // Add your authentication token or credentials here
          // For example, if using basic authentication:
          'Authorization': 'Basic ' + btoa('username:Password')
        },
      });

```

**Below is the working curl command for remote :**

```auto
Sunils-MacBook-Pro:kibana sunil$ curl -u username:password -k -X POST https://remotehost.domain.net/sample_jp_test_index/_doc -H 'Content-Type: application/json' -d '{ "acc_name": "Test_Account_1", "skill": "Skill_1" }'

{"_index":"sample_jp_test_index","_type":"_doc","_id":"1iwASo8BO8gkgOVa5ffK","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

Sunils-MacBook-Pro:kibana sunil$ 

```
