0

I'm wondering how can I do that # character should not be ignored when executing an api call.. I tried to use encodeURI and encodeURIComponent but still gets ignored and the api it's returning the response like I didn't use # at all. I mention that all other characters like $@!~` are not ignored, only this one # . Any hint will be appreciated. The service looks like this:

service.getCarByCarNumber = async car_number => {
  const carsReq = {
    headers: fetchApi.newHeaderWithToken(CAR_JWT, SITE_ID)
  };
  const result = await instance.get(
    `${API_GATEWAY_URL}${CAR_ENDPOINT}/carByNumber/${car_number}`,
    carsReq
  );

  return formatCarSearchRes(car);
};
  • 3
    Does this answer your question? [How to escape hash character in URL](https://stackoverflow.com/questions/5007352/how-to-escape-hash-character-in-url) – Keimeno Jul 30 '20 at 14:24
  • this is what encodeURIComponent does and still gets ignored by the API. My problem is that I have a search input and I need to search something by number, so when I type the number, the api gets called and returns the response. If I type 01234#, the api doesn't recognize # and returns the response like I typed 01234. If I use encodeURIComponent, the api gets called with 01234%23 but acts the same like above. So practically, this is my issue. –  Jul 30 '20 at 14:33
  • Can you please provide an example (a complete URL)? What you send to the API and what the API returns? – Keimeno Jul 30 '20 at 14:50
  • ok, so this is the request url http://localhost:3000/online/api/car/carByNumber/S0152%23 when I search by S0152# and returns the response like I've typed only S0152, without #. I've edited the post with the service code. –  Jul 30 '20 at 15:27
  • This isn't a problem with your client side code, as encodeURIComponent returns %23. What framework is your api written in? If It's written in express you can access the requested url by writing `req.originalUrl || req.url`. Can you please check if the API receives the #? – Keimeno Jul 30 '20 at 15:32
  • It's in express yes, in service I checked and it's received # also. If I search for 1234#, the service receives 1234#. –  Jul 30 '20 at 15:39
  • can you show the url that the api returns? and how it should look like as well? I think what's missing is, the api must convert the hash symbol back to a %23, but doesn't. – Keimeno Jul 30 '20 at 15:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/218915/discussion-between-christian-and-keimeno). –  Jul 30 '20 at 16:28

0 Answers0