1

I am using ApiBuilder in Java where my id path param has forward slashes ("/") because of encryption. However, the endpoint is not being found when run because the slashes are read as part of the URL, not as the id. Here is how I call the API request:

ApiBuilder.post("http://localhost:5008/api/update/{id}") {
// code process here
}

The sample id value is:

mxCSRO3qErTy7eO77HJeUvBiKXM/1i1cd3GdHuqdeSz/lyLU/N7cBCz3eZoIUyybhhmpAeJ1IABomr8Kv0IDKA==

Edit: I have already solved the issue here. According to javalin documentation, the path should be less_thanidgreater_than instead of {id}.

Dmitriy Popov
  • 2,150
  • 3
  • 25
  • 34
patani20
  • 11
  • 2

2 Answers2

0
String idValue = "mxCSRO3qErTy7eO77HJeUvBiKXM/1i1cd3GdHuqdeSz/lyLU/N7cBCz3eZoIUyybhhmpAeJ1IABomr8Kv0IDKA==";
String encodedId = URLEncoder.encode(idValue, StandardCharsets.UTF_8.toString());

String apiUrl = "http://localhost:5008/api/update/" + encodedId;

Use the uri like this,

And you can later modify your endpoint like this-

ApiBuilder.post(apiUrl) {
    // code process here
}
  • This is amazing! one of my problems is also how can I read the idValue from the url because the idValue must be dynamic – patani20 Aug 11 '23 at 11:38
0

You can replace all slashes (/) with %2F yourself. Here is a link to the encoding reference.

Or use this

    URLEncoder.encode(String s, String enc)
  • s — String to be translated.
  • enc — The name of a supported character encoding.

Example:

        private fun getUrl(): String {
             val idValue = "mxCSRO3qErTy7eO77HJeUvBiKXM/1i1cd3GdHuqdeSz/lyLU/N7cBCz3eZoIUyybhhmpAeJ1IABomr8Kv0IDKA=="
             val encodedId = URLEncoder.encode(idValue, StandardCharsets.UTF_8.toString())
             return "http://localhost:5008/api/update/$encodedId"
       }
Dmitriy Popov
  • 2,150
  • 3
  • 25
  • 34
Ivan Abakumov
  • 128
  • 1
  • 13
  • how can i read the id from the url using ApiBuilder? the idValue must be dynamic – patani20 Aug 11 '23 at 11:39
  • In your question, in the code example, you write that you are passing an ID. That means you're getting it from somewhere, right? – Ivan Abakumov Aug 11 '23 at 12:03
  • in javalin, you can use {id} in reading the id in a url path. but i think it doesn't consider forward slashes as an id – patani20 Aug 11 '23 at 15:32
  • nevermind, i have already solved the problem. as per the document, i should have coded instead of {id} to ignore slashes. thank you so much for answering – patani20 Aug 11 '23 at 15:52