clojure 스터디 luminus routing

12
Routing 클클클 클클클 2015-07-15 클클클

Upload: cheolhee

Post on 21-Jan-2017

352 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Clojure 스터디 Luminus Routing

Routing클로저 스터디 2015-07-15한철희

Page 2: Clojure 스터디 Luminus Routing

自己紹介• Java/Web, iOS Programmer• 6502 Assembly, FORTH, Haskell…• and Clojure !

Page 3: Clojure 스터디 Luminus Routing

Agenda

• Routing 이란 무엇인가• Luminus 의 Routing• HTTP Request 구조 ( 대충 )• Routing 예제 : URL 매칭패턴• 도움될 링크

Page 4: Clojure 스터디 Luminus Routing

Routing: 물류센터

Page 5: Clojure 스터디 Luminus Routing

Luminus 의 Routing

• Ring : Web Application Library• Compojure : a small routing library for Ring• HTTP method & URL 패턴 매칭 기반으로 동작

Page 6: Clojure 스터디 Luminus Routing

HTTP Request 구조• method : GET, POST, HEAD, PUT, DELETE…• URL : host, path, query• http://clojure.or.kr/wiki/doku.php?id=lecture:cl

ojure: 시작• clojure.or.kr -> host• /wiki/doku.php -> path• id=lecture:clojure: 시작 -> query

Page 7: Clojure 스터디 Luminus Routing

Routing 예제 : query

• (GET “/terminator” [name message]  (str name " said, \"" message "\"")) 

• http://localhost:3000/terminator?name=T-800&message=Hasta%20la%20vista,%20baby.

Page 8: Clojure 스터디 Luminus Routing

Routing 예제 : path

• (GET "/quotes/:words/:author" [words author] (str "\"" words "\" <br/> - " author))

• http://localhost:3000/quotes/I'll%20be%20back./T-800

Page 9: Clojure 스터디 Luminus Routing

Routing 예제 : path 2

•  (GET ["/file/:name.:ext" :name #".*", :ext #"(?i)jpe?g"]  [name ext]  (str "JPEG File: " name "." ext)) 

•  (GET ["/file/:name.:ext" :name #".*", :ext #"(?i)png"]  [name ext]   (str "PNG File: " name "." ext)) 

• http://localhost:3000/file/hello.JPEG • http://localhost:3000/file/hello.png

Page 10: Clojure 스터디 Luminus Routing

Routing 예제 : 아몰랑

• (compojure.route/not-found  "<h1>Page Not Found</h1>”)

• http://localhost:3000/who/am/i/and/where/am/i

Page 11: Clojure 스터디 Luminus Routing

리턴 밸류 : Response

• 간단하게는 그냥 String “ 만” 리턴한다 : text/html, utf-8 로 인식

• 응답코드 , Content-Type 을 지정하려면 map 을 리턴한다• (GET "/request-as-json" request

{:status 200 :headers {"Content-Type" "application/json"} :body (to-json request)} )

Page 12: Clojure 스터디 Luminus Routing

링크

• request , response 명세 • https://github.com/mmcgrana/ring/blob/master/SPEC• Compojure 는 다음 사이트 참고 • https://github.com/weavejester/compojure/wiki• 잠깐 봤으나 , 별로 참고는 안될 듯한 예제 . • https://github.com/weavejester/compojure-example