This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
Would prismatic schema superset something like validateur?
@pupeno: :body-params
uses Plumbing syntax: :body-params [x :- Long, {y :- Long 0}]
deraen: yes...
@pupeno: If you wanted to use Schema syntax you could use :body [{:keys [x y]} {:x Long, (s/optional-key :y) Long}]
I am using :body and schema syntax, I find it easier to read, but I’m not expressing it that way, I’m doing :body [user-data {:email String :password String}]
Yes, if you don't need to destructure the map it's easier to use :body
, and if you need to access fileds directly Plumbing syntax is useful
deraen: are you using compojure-api?
do you use the schema syntax? do you use separate schema definitions?
Separate schema definitions most often
Do you use those schemas only for the API or elsewhere in the code?
Depends. Sometimes they are used elsewhere but often the implementation Schema differs a bit. We use https://github.com/metosin/schema-tools to modify the Schemas so we can have something like (defschema User {...}) (defschema ImplUser (st/dissoc User ...))
deraen: do you use validateur for validation?
@pupeno: Just Schema. Sometimes we have to validate some stuff manually, like when date-a must be later than date-b and such which is not supported by Schema.
What’s the easiest way to handle returns while you are still defining the API? I suppose I could set it to String and manually convert my structures to json.
@pupeno: What do you mean? Just returns maps or what ever and compojure-api (ring-middleware-format) will take care of encoding to JSON/EDN/Transit depending on options and Accept header
@juhoteperi: what are you specifying an the :return when defining an API call?
:return
is not required for compojure-api to do the encoding
What libs are there for web-scrapping ? I found Enlive.
Ah… yeah, not defining :return is convenient.
lazy-lambda: it’s a bit strange, but I succesfuly did some web scrapping with enlive.
@pupeno: I have also scrapped with enlive before. It’s simple and awesome. I am wondering, are there any other libs focused on scrapping only ?
I don’t remember the alternatives, only that I ended up choosing enlive.
I’m using validateur to validate user input. So I have a function called user/create that might create a user (and return it) or return a list of validation errors. Both a success returning a user and errors are maps, so they are impossible to distinguish without looking into the map itself. What’s the appropriate way to handle this so that callers now what happened? Should I tag the output, like [:success, user-map] and [:error, validation-errors]? a-la Erlang?
@pupeno: Exceptions would be one possibility
deraen: I’m tempted… but this seems to be flow control, not exceptional situations. Having said that, they do feel good, but I do need the exception to carry a hashmap, is that possible? good style? will it explode on my face?
Sure exceptions can carry a hashmap and it's just fine to use them for flow control if it fits the use case.
deraen: how do you make them carry a clojure value?
ex-info
Thanks.
(throw (ex-info {:type :validation-error, :message ""}))
and then you could have a middleware to catch just those: (defn wrap-validation-error-handler [handler] (fn [req] (catch (handler req) (catch Exception e (let [m (ex-data e)] (if (#{:validation-error} (:type m)) {:body ... :status 500} (throw e))))))
@pupeno: Slingshot (https://github.com/scgilardi/slingshot) is very useful for throwing and catching maps
I kind of prefer the more lightweight https://github.com/gfredericks/catch-data
Is there a good way to parse command line arguments like this: ["--files" "a.edn" "b.edn" "c.edn" "--other" "args"]
and have all three files as the value like {:files ["a.edn" "b.edn" "c.edn"]}
?
but the only way I can see to do it with tools.cli is with :assoc-fn
and then I would have to pass ["--file" "a.edn" "--file" "b.edn" "--file" "c.edn"]
tools.cli ?
I don't remember how much flexibility you have there. Maybe a good enhancement.
Hey folks ... just put up a new quick library, io.aviso/logging -- https://github.com/AvisoNovate/logging.: - Sets up dependencies on SLF4J, Logback, clojure.tools.logging, pretty - Does all the pretty initialization - Includes the shim to convert Apache Commons Logging to SLF4J - Supports Ring request correlation This is just common stuff I always need when starting a new project.
@hlship: this looks excellent, thanks!