Hi Gary, 

You are right, the points that you mentioned are valid. Those things are 
already taken care of. I am new to Ring and Compojure so was trying out 
some stuff.
I was confused at some part, but now it got cleared and code if running as 
required.

Thanks for your time and reply.

On Monday, July 27, 2015 at 5:50:10 PM UTC+5:30, Gary Verhaegen wrote:

>
>
> On Monday, 27 July 2015, hemant gautam <gomz...@gmail.com <javascript:>> 
> wrote:
>
>> On running the below mentioned code on browser I am getting "Page not 
>> found" for each type of request.
>> Can anybody suggest me where I am doing a mistake. 
>>
>> (ns currentday.core
>> (:require [compojure.core :refer :all]
>>           [compojure.route :as route]
>>           [compojure.handler :as handler]
>>           [ring.middleware.defaults :refer :all]
>>           [ring.util.response :refer :all])
>> (:use ring.adapter.jetty))
>>
>> (defn now [] 
>>   (new java.util.Date))
>>
>> (defn say-hello []
>>    "Hello!! everyone. I am home page of webservice.")
>>
>> (defn date-is [req]
>>   "Today's date is: " (str (now)))
>>
>> (defn get-date [req]
>>    (-> (response (date-is))
>>        (content-type "text/html")))
>>
>> (defn add-data [a b]
>>    (-> (response "Sum of two no. is: "(str (+ a b)))
>>        (content-type "text/html")))
>>
>> (defn sub-data [a b]
>>    (-> (response "Subtraction of two no. is: "(str (- a b)))
>>        (content-type "text/html")))
>>
>> (defroutes my-routes
>>   (GET "/" [] "Hello")
>>   (GET "/date" req (get-date [req]))
>>   (GET "/add/:a/:b" [a b] (add-data a b))
>>   (GET "/sub/:a/:b" [a b] (sub-data a b))
>>   (route/not-found "Page not found"))
>>
>> (def app
>>       (handler/site my-routes))
>>
>> (defonce server (run-jetty #'app {:port 3032 :join? false}))
>>
>
> I'm not in a position to actually try that code, so I'm shooting blind. 
> Here are a few comments:
>
> * You do not seem to be using the ring.middleware.defaults, but instead 
> use the deprecated compojure.handler ns.
> * Your say-hello function is not used.
> * Your "/" route returns a String, which as far as I know is not a valid 
> ring response. Try with {:status 200 :body "Hello!"} instead of just a 
> string?
> * Your add and subtract handlers look like they should throw exceptions, 
> as you're calling response with 2 args and it's defined to receive a single 
> string argument.
> * From what I see here, I do not see any reason why the "/date" route does 
> not work.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to