Fork me on GitHub
#clojure
<
2015-08-02
>
Pablo Fernandez08:08:03

Would prismatic schema superset something like validateur?

juhoteperi08:08:43

@pupeno: :body-params uses Plumbing syntax: :body-params [x :- Long, {y :- Long 0}]

juhoteperi08:08:34

@pupeno: If you wanted to use Schema syntax you could use :body [{:keys [x y]} {:x Long, (s/optional-key :y) Long}]

Pablo Fernandez09:08:20

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}]

juhoteperi09:08:21

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

Pablo Fernandez09:08:05

deraen: are you using compojure-api?

Pablo Fernandez09:08:29

do you use the schema syntax? do you use separate schema definitions?

juhoteperi09:08:45

Separate schema definitions most often

Pablo Fernandez09:08:06

Do you use those schemas only for the API or elsewhere in the code?

juhoteperi09:08:06

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 ...))

Pablo Fernandez09:08:09

deraen: do you use validateur for validation?

juhoteperi09:08:20

@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.

Pablo Fernandez09:08:43

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.

juhoteperi09:08:20

@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

Pablo Fernandez09:08:01

@juhoteperi: what are you specifying an the :return when defining an API call?

juhoteperi09:08:17

:return is not required for compojure-api to do the encoding

lazy-lambda09:08:49

What libs are there for web-scrapping ? I found Enlive.

Pablo Fernandez09:08:21

Ah… yeah, not defining :return is convenient.

Pablo Fernandez09:08:45

lazy-lambda: it’s a bit strange, but I succesfuly did some web scrapping with enlive.

lazy-lambda09:08:05

@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 ?

Pablo Fernandez10:08:29

I don’t remember the alternatives, only that I ended up choosing enlive.

Pablo Fernandez10:08:47

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?

juhoteperi12:08:33

@pupeno: Exceptions would be one possibility

Pablo Fernandez12:08:47

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?

juhoteperi12:08:35

Sure exceptions can carry a hashmap and it's just fine to use them for flow control if it fits the use case.

Pablo Fernandez12:08:42

deraen: how do you make them carry a clojure value?

juhoteperi12:08:05

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

juhoteperi12:08:25

@pupeno: Slingshot (https://github.com/scgilardi/slingshot) is very useful for throwing and catching maps

mpenet16:08:36

I kind of prefer the more lightweight https://github.com/gfredericks/catch-data

jmmk17:08:55

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"]}?

jmmk17:08:18

The behavior I'm looking for would be like the nargs="+" in Python's argparse

jmmk17:08:22

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

Alex Miller (Clojure team)17:08:05

I don't remember how much flexibility you have there. Maybe a good enhancement.

hlship18:08:56

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.

danielcompton20:08:56

@hlship: this looks excellent, thanks!