Re: com.stuartsierra/component & ring/compojure example

2014-10-08 Thread Huahai Yang
This solution (creating the routes in a function and passing components 
into the function) seems to be the best solution. Other solutions all 
require defining the routes a prior, which may be the root of the problems, 
because some handlers may depend on functions generated by components in 
the run time.

-huahai


On Tuesday, October 7, 2014 10:42:14 PM UTC-7, Andrew Meredith wrote:
>
> This is not a full example, but I ran into the same issue when building an 
> app for the Clojure Cup not too long ago. The general approach I used is 
> this:
>
>- create the Compojure routes in a function with the components I need 
>as parameters
>- declare the web server itself (I used httpkit) as a component with 
>the dependencies needed for the routes
>- build a handler from the routes within the web server component's 
>start function, passing the dependencies into the route-generating function
>
> I'm no Clojure expert, and this was my first project using Stuart Sierra's 
> Component library, so I would be interested to hear some feedback from the 
> more seasoned Clojure folks here.
>
> Here is the relevant file from my project if you are interested: 
> https://github.com/kendru/tourbillon/blob/master/src/tourbillon/www/core.clj#L67
>
> On Tuesday, October 7, 2014 11:33:33 AM UTC, JPatrick Davenport wrote:
>>
>> Hello,
>> I'm trying to create a web app. I'm having the damnest time trying to 
>> figure out how to layer my application. I want to pass protocol 
>> implementations to the routes. The protocols define interacting with 
>> various data sources that I need down the way. 
>>
>> I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
>> What I can't find is an example project for component and compojure. 
>> Unfortunately the project com.stuartsierra/component is poorly named. 
>> Googling for component + compojure brings back mostly false positives.
>>
>> Does anyone have a gist or blog post about how to do this?
>>
>> Thanks,
>> JPD
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: com.stuartsierra/component & ring/compojure example

2014-10-08 Thread Juho Teperi
The Stuart Sierra's talk about Component has short bit about using it with 
ring, at around 32:24 .

Idea is that you'll wrap your basic routes with a middleware which will 
assoc components to every request.
Difference to the other approach (creating the routes using fn taking the 
components as params) is that you are referencing the routes through a var 
so you can update your routes by evaluating the route definition again and 
you don't need to reset the system.

I have a example here: https://gist.github.com/Deraen/9d65f447593859dd07ae. 
It also has some compojure-api stuff to enable easier access to components 
for the handlers.

On Tuesday, October 7, 2014 2:33:33 PM UTC+3, JPatrick Davenport wrote:
>
> Hello,
> I'm trying to create a web app. I'm having the damnest time trying to 
> figure out how to layer my application. I want to pass protocol 
> implementations to the routes. The protocols define interacting with 
> various data sources that I need down the way. 
>
> I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
> What I can't find is an example project for component and compojure. 
> Unfortunately the project com.stuartsierra/component is poorly named. 
> Googling for component + compojure brings back mostly false positives.
>
> Does anyone have a gist or blog post about how to do this?
>
> Thanks,
> JPD
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: com.stuartsierra/component & ring/compojure example

2014-10-08 Thread Daniel Szmulewicz
I posted a working example in the system repo: 

https://github.com/danielsz/system/tree/master/example

On Tuesday, October 7, 2014 2:33:33 PM UTC+3, JPatrick Davenport wrote:
>
> Hello,
> I'm trying to create a web app. I'm having the damnest time trying to 
> figure out how to layer my application. I want to pass protocol 
> implementations to the routes. The protocols define interacting with 
> various data sources that I need down the way. 
>
> I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
> What I can't find is an example project for component and compojure. 
> Unfortunately the project com.stuartsierra/component is poorly named. 
> Googling for component + compojure brings back mostly false positives.
>
> Does anyone have a gist or blog post about how to do this?
>
> Thanks,
> JPD
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: com.stuartsierra/component & ring/compojure example

2014-10-08 Thread Daniel Szmulewicz
1, Extract the app out of the Webserver record into its own var. 
2, Add to the Webserver record an additional argument called handler. 
2, Put the component in a separate namespace. 
3, Initialize your component with the app var. 

OR, use system, which does all of the above for you. 
https://github.com/danielsz/system/ 


I'll post an example application in the repo if people are interested.  

On Wednesday, October 8, 2014 8:42:14 AM UTC+3, Andrew Meredith wrote:
>
> This is not a full example, but I ran into the same issue when building an 
> app for the Clojure Cup not too long ago. The general approach I used is 
> this:
>
>- create the Compojure routes in a function with the components I need 
>as parameters
>- declare the web server itself (I used httpkit) as a component with 
>the dependencies needed for the routes
>- build a handler from the routes within the web server component's 
>start function, passing the dependencies into the route-generating function
>
> I'm no Clojure expert, and this was my first project using Stuart Sierra's 
> Component library, so I would be interested to hear some feedback from the 
> more seasoned Clojure folks here.
>
> Here is the relevant file from my project if you are interested: 
> https://github.com/kendru/tourbillon/blob/master/src/tourbillon/www/core.clj#L67
>
> On Tuesday, October 7, 2014 11:33:33 AM UTC, JPatrick Davenport wrote:
>>
>> Hello,
>> I'm trying to create a web app. I'm having the damnest time trying to 
>> figure out how to layer my application. I want to pass protocol 
>> implementations to the routes. The protocols define interacting with 
>> various data sources that I need down the way. 
>>
>> I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
>> What I can't find is an example project for component and compojure. 
>> Unfortunately the project com.stuartsierra/component is poorly named. 
>> Googling for component + compojure brings back mostly false positives.
>>
>> Does anyone have a gist or blog post about how to do this?
>>
>> Thanks,
>> JPD
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: com.stuartsierra/component & ring/compojure example

2014-10-07 Thread Andrew Meredith
This is not a full example, but I ran into the same issue when building an 
app for the Clojure Cup not too long ago. The general approach I used is 
this:

   - create the Compojure routes in a function with the components I need 
   as parameters
   - declare the web server itself (I used httpkit) as a component with the 
   dependencies needed for the routes
   - build a handler from the routes within the web server component's 
   start function, passing the dependencies into the route-generating function

I'm no Clojure expert, and this was my first project using Stuart Sierra's 
Component library, so I would be interested to hear some feedback from the 
more seasoned Clojure folks here.

Here is the relevant file from my project if you are interested: 
https://github.com/kendru/tourbillon/blob/master/src/tourbillon/www/core.clj#L67

On Tuesday, October 7, 2014 11:33:33 AM UTC, JPatrick Davenport wrote:
>
> Hello,
> I'm trying to create a web app. I'm having the damnest time trying to 
> figure out how to layer my application. I want to pass protocol 
> implementations to the routes. The protocols define interacting with 
> various data sources that I need down the way. 
>
> I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
> What I can't find is an example project for component and compojure. 
> Unfortunately the project com.stuartsierra/component is poorly named. 
> Googling for component + compojure brings back mostly false positives.
>
> Does anyone have a gist or blog post about how to do this?
>
> Thanks,
> JPD
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: com.stuartsierra/component & ring/compojure example

2014-10-07 Thread Daniel Szmulewicz
You may want to look here for integrating components in your app. 

https://github.com/danielsz/system/


On Tuesday, October 7, 2014 2:33:33 PM UTC+3, JPatrick Davenport wrote:
>
> Hello,
> I'm trying to create a web app. I'm having the damnest time trying to 
> figure out how to layer my application. I want to pass protocol 
> implementations to the routes. The protocols define interacting with 
> various data sources that I need down the way. 
>
> I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
> What I can't find is an example project for component and compojure. 
> Unfortunately the project com.stuartsierra/component is poorly named. 
> Googling for component + compojure brings back mostly false positives.
>
> Does anyone have a gist or blog post about how to do this?
>
> Thanks,
> JPD
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: com.stuartsierra/component & ring/compojure example

2014-10-07 Thread gaz jones
Here is a toy app that downloads nzbs from usenet:

https://github.com/gar3thjon3s/leacher

It's not documented, but it works. The component stuff is hooked up here:

https://github.com/gar3thjon3s/leacher/blob/master/src/clj/leacher/main.clj#L53



On 7 October 2014 12:33, JPatrick Davenport  wrote:

> Hello,
> I'm trying to create a web app. I'm having the damnest time trying to
> figure out how to layer my application. I want to pass protocol
> implementations to the routes. The protocols define interacting with
> various data sources that I need down the way.
>
> I saw Stuart Sierra's talk about Component. It looks to satisfy my needs.
> What I can't find is an example project for component and compojure.
> Unfortunately the project com.stuartsierra/component is poorly named.
> Googling for component + compojure brings back mostly false positives.
>
> Does anyone have a gist or blog post about how to do this?
>
> Thanks,
> JPD
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


com.stuartsierra/component & ring/compojure example

2014-10-07 Thread JPatrick Davenport
Hello,
I'm trying to create a web app. I'm having the damnest time trying to 
figure out how to layer my application. I want to pass protocol 
implementations to the routes. The protocols define interacting with 
various data sources that I need down the way. 

I saw Stuart Sierra's talk about Component. It looks to satisfy my needs. 
What I can't find is an example project for component and compojure. 
Unfortunately the project com.stuartsierra/component is poorly named. 
Googling for component + compojure brings back mostly false positives.

Does anyone have a gist or blog post about how to do this?

Thanks,
JPD

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.