Move "hy on meth" example to eg/.

This commit is contained in:
Berker Peksag 2014-01-14 05:59:44 +02:00
parent 8ababcb905
commit 25459177eb
2 changed files with 29 additions and 28 deletions

27
eg/flask/meth_example.hy Normal file
View File

@ -0,0 +1,27 @@
;;; Simple Flask application
;;;
;;; Requires to have Flask installed
;;;
;;; You can test it via:
;;;
;;; $ curl 127.0.0.1:5151
;;; $ curl -X POST 127.0.0.1:5151/post
;;; $ curl -X POST 127.0.0.1:5151/both
;;; $ curl 127.0.0.1:5151/both
(import [flask [Flask]])
(require hy.contrib.meth)
(setv app (Flask "__main__"))
(route get-index "/" []
(str "Hy world!"))
(post-route post-index "/post" []
(str "Hy post world!"))
(route-with-methods both-index "/both" ["GET" "POST"] []
(str "Hy to both worlds!"))
(apply app.run [] {"port" 5151})

View File

@ -1,5 +1,5 @@
;;; Meth ;;; Hy on Meth
;; based on paultag's meth library to access a Flask based application ;;; based on paultag's meth library to access a Flask based application
(defmacro route-with-methods [name path methods params &rest code] (defmacro route-with-methods [name path methods params &rest code]
"Same as route but with an extra methods array to specify HTTP methods" "Same as route but with an extra methods array to specify HTTP methods"
@ -25,29 +25,3 @@
(defmacro delete-route [name path params &rest code] (defmacro delete-route [name path params &rest code]
"Delete request" "Delete request"
`(route-with-methods ~name ~path ["DELETE"] ~params ~@code)) `(route-with-methods ~name ~path ["DELETE"] ~params ~@code))
;;; Simple example application
;;; Requires to have Flask installed
;; (import [flask [Flask]])
;; (setv app (Flask "__main__"))
;; (require hy.contrib.meth)
;; (print "setup / with GET")
;; (route get-index "/" [] (str "Hy world!"))
;; (print "setup /post with POST")
;; (post-route post-index "/post" [] (str "Hy post world!"))
;; (route-with-methods both-index "/both" []
;; (str "Hy to both worlds!") ["GET" "POST"])
;; (.run app)
;;; Now you can do:
;;; curl 127.0.0.1:5000
;;; curl -X POST 127.0.0.1:5000/post
;;; curl -X POST 127.0.0.1:5000/both
;;; curl 127.0.0.1:5000/both