Comments (6)
Liberator has the concept of representations. In liberator.representation
there is a Protocol Representation
which defines a single method as-response
. To convert a sequence to a json response the protocol would have to be implemented for sequences. The implementation then dispatches on the media-type to use clojure.data.json
in the case that the negotiated media-type is "application/json".
Fortunately there are already implementations for strings, sequences, maps, etc. for the media types text/plain, csv, tsv, application/clojure and application/json in liberator.representation
A simple resource definition would look like this:
(defresource me-can-haz-json
:available-media-types ["application/json"]
:handle-ok ["me" "can" "be" "a" {:application "json"}])
In the examples there a more resources, e.g. here: https://github.com/clojure-liberator/liberator/blob/master/examples/clj/examples.clj#L123
from liberator.
i already know about this, as i have changed the clojure.data.json function to use the latest version of cheshire on the version of liberator that i have pulled down and have been playing with.
i want to know about dealing with the request.
from liberator.
I'm not sure if I understand what you want? Do you man to automatically parse the request body?
from liberator.
yes
it's a stream, but if the user tells me they are sending me json, then i can run that stream through cheshire.
from liberator.
The most natural implementation IMHO is to use the valid-content-header? decision point:
(defresource foo
:valid-content-header?
(fn [ctx](when %28.equalsIgnoreCase "application/json" %28get-in ctx [:request "content-type"]))
{::parsed-content (parse-stream (get-in ctx [:request :body]))})))
Of course there is room for some to-be-written helper functionsm e.g.:
(parse-body "application/json" chesire/parse-stream "application/clojure" safe-parse-with-clojure-reader)
I'd be happy if you would contribute something like this.
from liberator.
that looks good.
from liberator.
Related Issues (20)
- handle-exception raises exception HOT 1
- Reliance on javax.xml.ws HOT 6
- `combine` results in a lazy seq for lists and vectors HOT 1
- "GC overhead limit exceeded" caused by liberator.dev/logs HOT 2
- render-seq-generic strange behaviour for "text/html" "text/plain" "text/csv" HOT 1
- Blocking upgrade to java 9 & 10 HOT 3
- Default handler responses returned are invalid JSON [Was: JSON representation issue when resource does not exist] HOT 3
- javax.xml.ws on java 11 HOT 2
- A new home for the examples? HOT 2
- Disable passing response options HOT 1
- include defaults in decision graph HOT 1
- Boss, midje has a very good automated test method . HOT 2
- Support 409 for PATCH requests. HOT 7
- wrap-trace not working with component middleware stack. HOT 2
- Unable to set a cookie.
- How to extract the form data from a request in liberator? HOT 1
- post-redirect? not working or Preflight response is not successful
- Authorization vs Authentication HOT 5
- The decisions page should provide details about implementing decisions HOT 3
- Fix CVE-2017-20189
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liberator.