1

I write a REST API with Clojure liberator, and I have this function, in order to build the URL:

(defn build-entry-url [request]
   (URL. (format "%s://%s:%s%s"
           (name (:scheme request))
           (:server-name request)
           (:server-port request)
           (:context request))))

Then I use halresource for representing resources and cheshire to parse the json. When I use curl, in json response the URL is showed as:

http:\/\/localhost:8080\/api\/customer\/1

But if I use some tool, like Postman, the URL is showed correctly

Any suggestion?

UPDATE: I re-checked and all json is generated correctly, but when I use curl, or trying access the end-point via browser, the URL is showed as: http:\/\/localhost:8080\/api\/customer\/1

Tim
  • 12,318
  • 7
  • 50
  • 72
Édipo Féderle
  • 4,169
  • 5
  • 31
  • 35
  • Something is escaping the string. If your just sending the url back as json, why create a url object with URL. before encoding into json? My guess is that either the URL object to string generates an escaped version or for some reason cheshire is escaping the string. Note that cheshire does have support for encoding urls, but you don't get it automatically, you have to specify it. – Tim X Sep 27 '15 at 02:10
  • Hi @TimX. So, I just drop all code from ``build-entry-url`` function and return a static string like "http://localhost..." and the url have the same "issue" yet. – Édipo Féderle Sep 28 '15 at 10:57
  • Most likely, something in your middleware or your defresource is escaping the string. I did a little test just using a basic ring/compojure template and a handler which returns a string url wrapped in a cheshire generate-string with no problems. Try manually calling (generate-sring("http://localhost:8080/api/1") and see if you get the same escaping. Might be useful to post your middleware and defresource definitions as well behaviour. If you do, then you need to look at your middleware. If you don't, it could be that – Tim X Sep 29 '15 at 02:40

0 Answers0