All Projects → ring-clojure → Ring Json

ring-clojure / Ring Json

Ring middleware for handling JSON

Programming Languages

clojure
4091 projects
ring
36 projects

Projects that are alternatives of or similar to Ring Json

Body Parser
Node.js body parsing middleware
Stars: ✭ 4,962 (+1611.03%)
Mutual labels:  middleware, json
Muuntaja
Clojure library for fast http api format negotiation, encoding and decoding.
Stars: ✭ 304 (+4.83%)
Mutual labels:  middleware, json
Django Ajax
Fast and easy AJAX libraries for django applications. Contains ajax decorator, ajax middleware, shortcuts and more.
Stars: ✭ 312 (+7.59%)
Mutual labels:  middleware, json
Apicache
Simple API-caching middleware for Express/Node.
Stars: ✭ 957 (+230%)
Mutual labels:  middleware, json
Redux Json Router
Declarative, Redux-first routing for React/Redux browser applications.
Stars: ✭ 37 (-87.24%)
Mutual labels:  middleware, json
Tesla
The flexible HTTP client library for Elixir, with support for middleware and multiple adapters.
Stars: ✭ 1,588 (+447.59%)
Mutual labels:  middleware, json
Graphql Factory
A toolkit for building GraphQL
Stars: ✭ 44 (-84.83%)
Mutual labels:  middleware, json
Goat
[DEPRECATED] 🐐 A minimalistic JSON API server in Go
Stars: ✭ 161 (-44.48%)
Mutual labels:  middleware, json
Ojg
Optimized JSON for Go
Stars: ✭ 281 (-3.1%)
Mutual labels:  json
Openremote
100% open-source IoT Platform - Integrate your assets, create rules, and visualize your data
Stars: ✭ 254 (-12.41%)
Mutual labels:  middleware
Quranjson
Quran JSON ~ 6236 verses, 114 surah, 30 Juz
Stars: ✭ 278 (-4.14%)
Mutual labels:  json
Serpent
A protocol to serialize Swift structs and classes for encoding and decoding.
Stars: ✭ 281 (-3.1%)
Mutual labels:  json
Json Flattener
A Java utility is used to FLATTEN nested JSON objects and even more to UNFLATTEN it back
Stars: ✭ 285 (-1.72%)
Mutual labels:  json
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (-3.79%)
Mutual labels:  middleware
Ring Defaults
A library to provide sensible Ring middleware defaults
Stars: ✭ 289 (-0.34%)
Mutual labels:  middleware
Product Ei
An open source, a high-performance hybrid integration platform that allows developers quick integration with any application, data, or system.
Stars: ✭ 277 (-4.48%)
Mutual labels:  middleware
Urs
Universal Reddit Scraper - A comprehensive Reddit scraping command-line tool written in Python.
Stars: ✭ 275 (-5.17%)
Mutual labels:  json
Visualjson
JSON pretty-viewer for OS X.
Stars: ✭ 290 (+0%)
Mutual labels:  json
React Docgen
A CLI and toolbox to extract information from React component files for documentation generation purposes.
Stars: ✭ 3,143 (+983.79%)
Mutual labels:  json
Slack History Export
A NPM module that allows slack users export their history
Stars: ✭ 284 (-2.07%)
Mutual labels:  json

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.5.0"]

Usage

wrap-json-response

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

(require '[ring.middleware.json :refer [wrap-json-response]]
         '[ring.util.response :refer [response]])

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

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

wrap-json-body

The wrap-json-body middleware will parse the body of any request with a JSON content-type into a Clojure data structure, and assign it to the :body key.

This is the preferred way of handling JSON requests.

(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}))

wrap-json-params

The wrap-json-params middleware is an alternative to wrap-json-body for when it's convenient to treat a JSON request as a map of parameters. Rather than replace the :body key, the parsed data structure will be assigned to the :json-params. The parameters will also be merged into the standard :params map.

(require '[ring.middleware.json :refer [wrap-json-params]]
         '[ring.util.response :refer [response]])

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

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

Note that Ring parameter maps use strings for keys. For consistency, this means that wrap-json-params does not have a :keywords? option. Instead, use the standard Ring wrap-keyword-params function:

(require '[ring.middleware.keyword-params :refer [wrap-keyword-params]])

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

License

Copyright © 2019 James Reeves

Distributed under the MIT License, the same as Ring.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].