-2

I have created a Rest API using Python Hug which accepts a list as a parameter.

Python REST API code

import hug
@hug.get('/myFunc/')
def myFunc(textList)
   print(len(textList))
   print(type(textList))

Java Code

List<String> textArr = new ArrayList<String>(); 
File htmlsFolder =  new File(#html Folder Path);
try {
File[] files = htmlsFolder.listFiles();
for (File file : files) {    
html = new String(Files.readAllBytes(Paths.get(file.getPath())));
Document doc = Jsoup.parse(html); 
textArr.add(doc.body().text().replaceAll("[\\n\\t\\r\\s+]", " ")); 
}  
System.out.println(textArr.size());
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders(); 
HttpEntity<String> entity = new HttpEntity<String>(null, headers);
ResponseEntity<String> response = restTemplate.exchange("http://apiurl/myFunc?textList="+textArr.toString(), HttpMethod.GET, entity, String.class);

Java code reads/parses html files from a folder path and stores the content in an arrayList. If there are 17 html files, then the size of arrayList is 17. When the Python REST API is called, and I print the length of list on python side, the length of list items is not the same, it is somewhere around 500. Is this due to sending the parameter as a query string in the GET request or there is conversion issue between Java arrayList and Python List?

System.out.println(textArr.size()); #gives 17 (Java Code)

print(len(textList)) #gives 543 (Python Code)

jacob mathew
  • 143
  • 1
  • 11

1 Answers1

2

the issue has been resolved, by making the api as a POST method, passing the value from Java as request body and fetching the input as body on Python side.

import hug
@hug.post('/myFunc/')
def myFunc(body)
   textList = body['textList']
jacob mathew
  • 143
  • 1
  • 11