Skip to content

pbudzik/legion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Legion - Minimalistic REST services framework for Clojure

Core concepts

  • succinct but expressible -> lots of macros used, less is more
  • convention over configuration -> save time by typing less
  • netty/http/json -> simple
  • server/client unified -> both share the same conventions
  • scalable -> not about one instance, but many
  • clustered -> join a cluster and work w/o configuration
  • failover -> many nodes
  • leightweight -> not many dependencies, no external processes needed
(defproject my-project "1.0.0"
  :dependencies [[org.clojure/clojure "1.3.0"]
				 [legion "1.0.0-SNAPSHOT"]])

Starting services

(defn my-handler [rq] (response 200 {:firstname "John" :lastname "Doe" :email "John.Doe@foo.com"}))

(defservices my-services
  (GET "/user/:id" my-handler))

Defining service consumer

(defclient get-user {:cluster "my-cluster" :uri "/user"} [id])

By convention it is GET. It builds a dedicated consumer function to GET this service with an argument "id". It also creates a function to destroy it when done to disconnect from the cluster. Note, it only needs to know the cluster name.

Consuming services

(let [services (cluster-start "my-cluster" 8080 my-services)]
  (try
    (println (get-user 19811))
    (finally
      (cluster-stop services)
      (get-user-destroy))))

Result

{:status 200, :headers {content-type text/plain; charset=UTF-8}, :body {"email":"John.Doe@foo.com","firstname":"John","lastname":"Doe"}}

About

REST framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published