Can't figure how to pass a file path to the GET in spark-java micro service

284 Views Asked by At

I have an HTTP GET defined like below in a spark-java microservice, that using POI, will return the Word document's text.

The problem I have (and it's probably simple to fix), is that I can't pass a path to the GET since it misinterprets it.

I've tried escaping the path, putting name=value, quotes, etc., but it doesn't work yet.

If I set the path inside the actual micro-service, then it's all good. Therefore, I'm just confused how to set a path in the GET.

Should be something close to: $curl localhost:4567/docxtext/Test.docx

(but allowing a path for the "Text.docx" part -- for example, "./Test.docx")

Thanks for any suggestions!

  • m

    get("/docxtext/:docName", (request, response) -> { return getWordDocText(request.params("docName")); });

2

There are 2 best solutions below

0
On

It can be solved by using query params, like the following:

http://127.0.0.1:1234/docxtext?docName=yourEscapedPath

get("/docxtext", (request, response)->{
  String docName = request.queryParams("docName");
  return "HI";
}
0
On

Yep, that worked. Thanks. I just needed to substitute %2 for / and it worked fine. Appreciate your reply. Thanks again.