Fork me on GitHub
#yada
<
2016-09-03
>
eslachance00:09:52

Am I absolutely going nuts or is it possible that whenever I start Edge it fires a sound? like, a "bloop"???

eslachance00:09:43

Yeah it... definitely does. right after "Writing target dir(s)...

kingoftheknoll04:09:44

So this is going to sound crazy but hear me out. Rome wasn’t built in a day and I’ve got 3 yr old Python Flask web server where 80% of the functionality must lie for the time being. While I’m planning for the long term, my immediate goal is to optimize for lots of concurrent users for just a few endpoints where Python is never going to cut it. Yada seems like the perfect fit for short and long term goals. However I’m left with a challenge, I can’t have the browser talking to two web servers. So my thought is to treat yada as a proxy for any routes that bidi does not match to the python server with aleph.http and returning the response exactly to the client. I see two ways of doing this by creating a handler for bidi’s 404 or the ‘/‘ root url to do either: 1) Use yada handler where all methods are specified

(resource
  {:methods
    {:get (fn [ctx] (get "”))
      ;; all other methods }})
- this will only work if swagger does no validation and not having an actual url doesn’t mess up yada. I could also think of putting this handler at the root url. 2) Do my own ring/response handler at ‘/‘ or 404 - I’m most certain that yada parses the routes would this blow it up? Also a more general question along those lines is, can you exclude endpoints from swagger docs and/or validation? Sorry this is a bit long and weird, hopefully you see where I’m coming from. Any advise will be appreciated! I’ll be attempting to put this together tomorrow so we’ll see how it goes 😃

kingoftheknoll04:09:27

Actually you couldn’t do it on ‘/‘ because you wouldn’t match. It has to be 404

dominicm06:09:32

@eslachance: that's a task to let you know recompilation succeeded. It's the speak task, feel free to remove it if you hate it. You can also make the sounds cooler. Checkout boot speak -h

dominicm06:09:48

@kingoftheknoll: yada makes a REALLY good proxy. If you use the aleph http client, you can do all the requests async, and yada will return the exact response they return. It's like voodoo. You'd want to do it in the 404 url style, yep 😃

dominicm06:09:57

I'm pretty sure you can exclude from swagger somehow, and skip the yada validation by using things like {s/Any s/Any} in validation positions. There might be another way that involves extending protocols, but I wouldn't be sure of the implementation. It would be similar to yada's resource and file implementations which you can find in the source.

frozenlock06:09:39

dominicm : got any proxy example laying around?

frozenlock06:09:56

I might have to test one of a my app for proxy capabilities, so having a yada proxy server to test everything would be perfect 🙂

malcolmsparks09:09:13

@kingoftheknoll: read up on path-info? in the Resources chapter. If you set path info to true, bidi will match on a partial path like /, so /foo will be matched and the request will contain a path-info value of foo.

malcolmsparks09:09:35

This way you can process all URIs with a single handler. There's also a way to match on all methods. I think it's :* but would need to check

malcolmsparks09:09:18

But I would caution that if you aren't making use of yada's core featureset you may be better off making your an Aleph handler - see aleph's own docs - yada is just a factory for building such thingd

eslachance10:09:45

btw @malcolmsparks your blog post should be the readme for edge repo. It really should. 😛

dominicm13:09:23

Its slightly outdated, as yada changed quite a bit.

dominicm13:09:07

But the method works still.

malcolmsparks18:09:10

Doc bug. Add a :produces entry. That 406 is the clue

kingoftheknoll18:09:50

What should i put there? Most examples in the docs say produces ‘text/plain’ or something. Here I’m returning a deferred

malcolmsparks18:09:43

Put all the types you are able to return.

malcolmsparks19:09:46

Yes, you can return a deferred value from yada, but you need to know the content types of that value for the content negotiation phase to complete. If this is dynamically determined, use a sub-resource

malcolmsparks19:09:39

@kingoftheknoll: do you know the content type of the content you are serving?

malcolmsparks19:09:31

I'm not 100% sure the role of a proxy in content negotiation.

malcolmsparks19:09:50

This is an interesting use-case

kingoftheknoll20:09:11

@malcolmsparks that worked! I’ll use the sub-resource stuff when I do the full setup. Just testing if I can pass the response back through bun ran into one problem. So it looks like the Async example given won’t work automatically because the body of a response provided by Aleph.http is a java.io.ByteArrayInputStream. Request is made but

15:52:57.137 [aleph-netty-server-event-pool-20-3] ERROR aleph.http.core - error sending body of type  aleph.http.core.NettyResponse
java.lang.IllegalArgumentException: Don't know how to convert class aleph.http.core.NettyResponse into (stream-of io.netty.buffer.ByteBuf)

kingoftheknoll20:09:50

Sorry for the delay and such helping the wife clean the house 😃

lmergen21:09:06

@kingoftheknoll: can you please share the code that causes this ?

lmergen21:09:29

or is it an actual example in the yada repo ?

lmergen22:09:36

I think what you want is (manifold.deferred/chain (http/get ....) :body)

lmergen22:09:00

you're returning the entire response with all its metadata, rather than the response body.

kingoftheknoll22:09:11

@lmergen that makes perfect sense. I’ll give it a test here in a min. Thanks!

lmergen22:09:58

np. let me know whether it worked.