Giter VIP home page Giter VIP logo

crud's Introduction

crud

Build Status Documentation Stories in Ready

As a developer, I want to be able to describe a resource's high-level details like data data integrity, associations, documentation etc. and have a system that builds a corresponding API and user interface so that I can focus on tooling for higher value activities like integration with other systems or data analysis.

Basic Example

The following program implements a "tweet" API with the following features

  • GET/POST/PATCH/DELETE "tweets" with :created_at, :authored_by and :msg attributes
  • For POST and PATCH, ensure that :msg is <144 characters
  • GET a list of tweets matching the specified parameters
  • GET "/api/doc" for swagger documentation for the Tweet and User resources
  • When persisting the User resource, :secret is filtered through the bcrypt algorithm
(ns crud.twitter
  (:require [crud :refer :all]
            [prismatic.schema :as s]))

(defentity User
  :schema {:id s/Int
           :email s/Str
           :name s/Str
           :secret s/Str}
  :uniqueness {:id :db.unique/identity})

(defentity Tweet
  :schema {:id s/Int
           :created-at Date
           :msg s/Str}
  :links [(link :authored-by [User :id])]
  :uniqueness {:id :db.unique/identity})

(let [entities [User Tweet]
      db (crud-db {:type :datomic
                   :uri "datomic:mem://tweet-db"
                   :entities entities})]
  (run-jetty (hypercrud {:db db, :entities entities})
             {:port 3000}))

OK. Lets make sure we're not flagrently violating security principles by storing the secret in plain text. The example below encrypts the :secret attribute before persisting it to storage

(ns crud.twitter
  (:require [crypto.password.bcrypt :as password]
            [prismatic.schema :as s]))

(defn encrypt [attr] (fn [params]
                       (password/encrypt (attr params))))

(defentity Tweet
  :schema {:id s/Int
           :created-at Date
           :authored-by User
           :msg s/Str}
  :links [(link :authored-by [User :id])]
  :storage [:email :name (encrypt :secret)]}

License

Copyright © 2014 Andy Chambers

crud's People

Contributors

cddr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.