Fork me on GitHub
#yada
<
2015-07-15
>
malcolmsparks18:07:56

I've been working on yada a lot recently and the 0.5.x branch is nearing completion - just a few more tests to fix and work on the documentation, should be just a couple of weeks now

gjnoonan19:07:59

What are some (major?) differences between 0.53 and 0.5 ?

malcolmsparks20:07:26

the most important difference is that yada 0.5 promotes state to being 'first class' - all yada resources are associated with some state (mutable or immutable) - for example (yada "Hello World") yields a Ring handler still, but the state is a string

malcolmsparks20:07:38

yada then teases out all the possible properties of that state, so for the example above, we can't tell the content-type, we can know that a java string can be represented in a variety of charsets

malcolmsparks20:07:29

it doesn't sound too much, but it's a profound change - you can use Files as state, or even whole directories, or other things like database tables, redis stores, and other things

malcolmsparks20:07:05

in the (yada "Hello World") we can tell the last-modified time of the string (the time the yada function was called)

malcolmsparks20:07:38

but we can also do (yada (atom "Hello World")) and yada adds a watch to detect changes that it can then report as the last-modified property

malcolmsparks20:07:18

there are quite a few built-in types of state you can use, but you can add your own via defrecord - of course there is a single Resource protocol behind all this

malcolmsparks20:07:44

A single function is also considered to be a valid state, so (yada (fn [ctx] {:status 415 :body "I'm a teapot"}))

malcolmsparks20:07:15

will work too, where (:method ctx) is the method

malcolmsparks20:07:03

Content negotiation is also greatly overhauled - you can specify possible representations at a vector of maps like this:

malcolmsparks20:07:55

[{:method :get :content-type #{"text/html" "text/plain"} :charset #{"latin1" "utf-8"} :language #{"en-US" "fr-FR"}}  {:method :post :content-type #{"application/json"}}]

malcolmsparks20:07:20

So you can specify that you can serve a resource in the Chinese language in Shift_JIS encoding, and English in US-ASCII, but not vice-versa - and do this with method, content-type, charset, language, content-encoding and transfer-encoding - it's quite powerful

malcolmsparks20:07:11

But generally speaking, new yada users should not notice this state abstraction going on, yada will (i hope) 'just work' and 'do the right thing' in the majority of cases

malcolmsparks20:07:01

Everything still works with Swagger, and there is support for sync and async for almost every operation

malcolmsparks20:07:51

0.5 also has a full comprehensive test suite

malcolmsparks20:07:36

Also, all methods are now backed by a Method protocol, and you can define your own methods (if you must)