Git Product home page Git Product logo

ring-json's Introduction

Ring-JSON

Build Status

Standard Ring middleware functions for handling JSON requests and responses.

Installation

To install, add the following to your project :dependencies:

[ring/ring-json "0.3.1"]

Usage

The wrap-json-response middleware will convert any response with a collection as a body (e.g. map, vector, set, seq, etc) into JSON:

(use '[ring.middleware.json :only [wrap-json-response]]
     '[ring.util.response :only [response]])

(defn handler [request]
  (response {:foo "bar"}))

(def app
  (wrap-json-response handler))

The wrap-json-body middleware will parse the body of any request with a JSON content-type into a Clojure data structure:

(use '[ring.middleware.json :only [wrap-json-body]]
     '[ring.util.response :only [response]])

(defn handler [request]
  (prn (get-in request [:body "user"]))
  (response "Uploaded user."))

(def app
  (wrap-json-body handler {:keywords? true :bigdecimals? true}))

The wrap-json-params middleware will parse any request with a JSON content-type and body and merge the resulting parameters into a params map:

(use '[ring.middleware.json :only [wrap-json-params]]
     '[ring.util.response :only [response]])

(defn handler [request]
  (prn (get-in request [:params "user"]))
  (response "Uploaded user."))

(def app
  (wrap-json-params handler))

License

Copyright © 2014 James Reeves

Distributed under the MIT License, the same as Ring.

ring-json's People

Contributors

weavejester avatar aeronotix avatar aviflax avatar daviddpark avatar jmglov avatar jvah avatar laczoka avatar michaelklishin avatar boxxxie avatar ryfow avatar

Watchers

 avatar James Cloos 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.