Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.
/ hat Public archive

HAT (The Hypermedia API Toolkit) lets you build RESTful HTTP CRUD APIs that compose cleanly with your ring application.

License

Notifications You must be signed in to change notification settings

silverpond/hat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HAT: The Hypermedia API Toolkit

HAT logo

HAT lets you build RESTful HTTP CRUD APIs that compose cleanly with your ring application.








Usage

; Resource description
(defn hosts-description [database-connection]
  (generate-description {:singular-name      "host"
                         :singular-titlecase "Host"
                         :plural-name        "hosts"
                         :plural-titlecase   "Hosts"
                         :conn               database-connection
                         :db-search-attr     :host/name
                         :fields             #(do [{:title "Name"
                                                    :name  :host/name
                                                    :type  :text}]})))

; Auth
(def all-roles #{:public :user :admin})

(def admin-only #{:admin})

(def authorisation-rules
  {:index  {:get all-roles}
   :hosts  {:get all-roles :post admin-only}
   :host   {:get all-roles :put  admin-only :delete admin-only}
   :events {:get all-roles :post admin-only}
   :event  {:get all-roles :put  admin-only :delete admin-only}})

(defn authenticate
  ([]
   {:roles #{:public}})
  ([username password]
   (if (= password "adminpassword")
     {:username username
      :roles    all-roles})))

; Compose and start
(defn -main []
  (let [conn   (db/connect "datomic:dev://datomic:4334/some-database")
        hosts  (hosts-description conn)
        events (events-description conn)]
    (-> (controllers/the-intermediate-step [hosts events])
        (one-to-many hosts events :host/name :event/host)
        (install-auth authenticate authorisation-rules)
        controllers/start)))

Todo

  • Improve documentation.
  • Add validation support.
  • Possibly split out the datomic persistance into an adapter library.
  • Write persistance layers for PostgreSQL, MySQL, SQLite.

License

Copyright © 2014 Silverpond

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

HAT (The Hypermedia API Toolkit) lets you build RESTful HTTP CRUD APIs that compose cleanly with your ring application.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published