Giter Club home page Giter Club logo

sweet-liberty-example's Introduction

Sweet Liberty Example

This is a simple example project meant to demonstrate how to use Sweet Liberty (github repo). Here's a blog post about the library.

This application exposes a RESTful interface that can be used to perform CRUD operations on dog records contained in an in-memory database. This example can be used as a template for more sophicated projects built using Sweet Liberty.

Try it out

Drop some knowledge on your terminal:

$ git clone https://github.com/RJMetrics/sweet-liberty-example.git
$ cd sweet-liberty-example
$ lein ring server-headless

Once the server has started successfully, the terminal should show:

Started server on port 3000

From another terminal, type:

$ curl http://localhost:3000/dogs

You should see a response like:

[{"breed":"poodle","name":"Fido","id":1},{"breed":"corgi","name":"Lacy","id":2},{"breed":"chihuahua","name":"Rex","id":3},{"breed":"dalmation","name":"Spot","id":4},{"breed":"chihuahua","name":"Taco","id":5},{"breed":"corgi","name":"Brody","id":6}]

You just let the dogs out.

sweet-liberty-example's People

Contributors

bpiel avatar looselytyped avatar

Stargazers

yāλu avatar Pete Doherty avatar Maciej Łotysz avatar Sam Stiles avatar anton avatar Edham Arief Dawillah / edthix avatar Brian Sloane avatar Corey Williams avatar Alan Meira avatar Jonathan Grahl avatar Lynn Dylan Hurley avatar Bradford W avatar Ben Garvey avatar Kyle Burton avatar

Watchers

 avatar  avatar TJ avatar James Cloos avatar  avatar

Forkers

looselytyped

sweet-liberty-example's Issues

Logging coll's throws invalid JSON Exception

Friend the Clojure authentication library attaches a collection of authentication fn / handlers which sweet-lib throws up on trying to parse as JSON.

Example:

[false false true false]
parsing: {}
[false false true false]
parsing: {}
[false false true false]
parsing: nil
[false false false true]
parsing: nil
[false false false true]
parsing: {}
[false false true false]
parsing: nil
[false false false true]
parsing: {}
[false false true false]
parsing: /users
[false true false false]
parsing: {}
[false false true false]
parsing: {:default-landing-uri /app, :login-uri /login, :credential-fn #object[budget_om.server$fn__28154 0x699d4a7c budget_om.server$fn__28154@699d4a7c], :workflows [#object[cemerick.friend.workflows$interactive_form$fn__19471 0x39b10857 cemerick.friend.workflows$interactive_form$fn__19471@39b10857]], :unauthenticated-handler #object[budget_om.server$fn__28152 0x4dee8226 budget_om.server$fn__28152@4dee8226]}
[false false true false]
parsing: /app
[false true false false]
parsing: /login
[false true false false]
parsing: #object[budget_om.server$fn__28154 0x699d4a7c budget_om.server$fn__28154@699d4a7c]
[false false false false]
parsing: [#object[cemerick.friend.workflows$interactive_form$fn__19471 0x39b10857 cemerick.friend.workflows$interactive_form$fn__19471@39b10857]]
[false false true false]

That last line [#object[cemerick.friend.workflows$interactive_form$fn__19471 0x39b10857 cemerick.friend.workflows$interactive_form$fn__19471@39b10857]] is a Vector of 1 object which cannot be JSON parsed as is.

Resulting in:

{:status 500, :headers {"Content-Type" "application/edn;charset=UTF-8", "Vary" "Accept", "Set-Cookie" ("ring-session=d22473ed-4e13-4a90-943f-3d2d9a669118;Path=/;HttpOnly"), "X-XSS-Protection" "1; mode=block", "X-Frame-Options" "SAMEORIGIN", "X-Content-Type-Options" "nosniff"}, :body "{\"exception-message\":\"Don't know how to write JSON of class cemerick.friend.workflows$interactive_form$fn__19471\"

Was able to get around this with:

(defn json-value-fn
  ([v]
   (if (coll? v)
     (apply str (map json-value-fn v)))
   (if (or (number? v) (string? v) (nil? v))
     v
     (str v)))
  ([_ v] (json-value-fn v)))

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.