-1

I have a requirement where we make an api call and it contains "/" in the rest api uri. For example, www.abc.com/books/bookid/1232kkjf/asdis/waew. The bold string is the book id and it contains "/". When we use it, we receive error.

If it is possible to use "/", please help me with some details. Appreciate your help!!

Anant Dabhi
  • 10,864
  • 3
  • 31
  • 49
Madhu
  • 21
  • 2

2 Answers2

0

Whenever you have path parameters that comprises of special characters like '/' you must perform URL encoding. While creating your HTTP request you must encode "1232kkjf/asdis/waew" with

If you are using Java Client then use URLEncoder

String myEncodedPathParam = URLEncoder.encode(rawParm, "UTF-8");

I you are using any other client like PostMan then you can use a lot of online tools that convert string to URLEncoded UTF-8 ex. https://www.url-encode-decode.com/

This way / will be replaced by %2F

piy26
  • 1,574
  • 11
  • 21
0

You need to replace it with '%2F' in the string. See similar question: How do I pass the # symbol as part of a GET querystring in the URL?

Also see this link: https://www.degraeve.com/reference/urlencoding.php

kban
  • 150
  • 1
  • 9