Shell

curl -d '{"file": "/tmp/test"}' -H 'Content-Type: application/json' http://172.31.39.37:8080/api/clamav/scan/file

Python

import requests
import json

def elm_scan_file(url, file):
    # Define the payload as a dictionary
    payload = {
		"file": file
	}

    # Set the headers
    headers = {
        "Content-Type": "application/json"
    }

    # Send a POST request to the API endpoint
    response = requests.post(url, data=json.dumps(payload), headers=headers)

    # Check the response status code
    if response.status_code == 200:
        # Request was successful
        data = response.json()  # Extract the JSON data from the response
        return data
    else:
        # Request was not successful
        print(f"Request failed with status code: {response.status_code}")
        return None

if __name__ == '__main__':        
    result = elm_scan_file(
        url = "http://172.31.39.37:8080/api/clamav/scan/file", \
        file = '/tmp/virus_test.txt')
    
    if result:
        print(result)
        print(result['code'])
        print(result['message'])

JavaScript

const axios = require('axios');

async function elmScanFile(url, file) {
  try {
    const payload = {
	  file
    };

    const headers = {
      'Content-Type': 'application/json',
    };

    const response = await axios.post(url, payload, { headers });

    if (response.status === 200) {
      return response.data;
    } else {
      console.log(`Request failed with status code: ${response.status}`);
      return null;
    }
  } catch (error) {
    console.error('An error occurred:', error.message);
    return null;
  }
}

async function main() {
  const url = 'http://172.31.39.37:8080/api/clamav/scan/file';
  const file = '/tmp/virus_test.txt';

  const result = await elmScanFile(url, file);

  if (result) {
    console.log(result);
    console.log(result.code);
    console.log(result.message);
  }
}

main();

Dart

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<Map<String, dynamic>?> elmScanFile(String url, String file) async {
  try {
    final payload = {
      'file': file
    };

    final headers = {
      'Content-Type': 'application/json',
    };

    final response = await http.post(Uri.parse(url), headers: headers, body: jsonEncode(payload));

    if (response.statusCode == 200) {
      return jsonDecode(response.body);
    } else {
      print('Request failed with status code: ${response.statusCode}');
      return null;
    }
  } catch (error) {
    print('An error occurred: $error');
    return null;
  }
}

void main() async {
  final url = 'http://172.31.39.37:8080/api/clamav/scan/file';
  final file = '/tmp/virus_test.txt';

  final result = await elmScanFile(url, file);

  if (result != null) {
    print(result);
    print(result['code']);
    print(result['message']);
  }
}

Go

package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)

func elmScanFile(url string, file string) (map[string]interface{}, error) {
	payload := map[string]interface{}{
		"file":    file
	}

	payloadBytes, err := json.Marshal(payload)
	if err != nil {
		return nil, err
	}

	req, err := http.NewRequest("POST", url, bytes.NewBuffer(payloadBytes))
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	resp, err := client.Do(req)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	respBody, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	if resp.StatusCode == http.StatusOK {
		var data map[string]interface{}
		err = json.Unmarshal(respBody, &data)
		if err != nil {
			return nil, err
		}
		return data, nil
	} else {
		return nil, fmt.Errorf("Request failed with status code: %d", resp.StatusCode)
	}
}

func main() {
	url := "http://172.31.39.37:8080/api/clamav/scan/file"
	file := "/tmp/virus_test.txt"

	result, err := elmScanFile(url, file)
	if err != nil {
		fmt.Println("An error occurred:", err)
		return
	}

	if result != nil {
		fmt.Println(result)
		fmt.Println(result["code"])
		fmt.Println(result["message"])
	}
}