You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+19-14Lines changed: 19 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,20 @@
6
6
7
7
Aleph exposes data from the network as a [Manifold](https://github.com/clj-commons/manifold) stream, which can easily be transformed into a `java.io.InputStream`, [core.async](https://github.com/clojure/core.async) channel, Clojure sequence, or [many other byte representations](https://github.com/clj-commons/byte-streams). It exposes simple default wrappers for HTTP, TCP, and UDP, but allows access to full performance and flexibility of the underlying [Netty](https://github.com/netty/netty) library.
8
8
9
-
```clj
10
-
[aleph "0.4.7"]
9
+
Leiningen:
10
+
```clojure
11
+
[aleph "0.5.0-rc2"]
12
+
```
13
+
deps.edn:
14
+
```clojure
15
+
aleph/aleph {:mvn/version"0.5.0-rc2"}
11
16
```
12
17
13
18
### HTTP
14
19
15
-
Aleph follows the [Ring](https://github.com/ring-clojure) spec fully, and can be a drop-in replacement for any existing Ring-compliant server. However, it also allows for the handler function to return a [Manifold deferred](https://github.com/clj-commons/manifold) to represent an eventual response. This feature may not play nicely with synchronous Ring middleware which modifies the response, but this can be easily fixed by reimplementing the middleware using Manifold's [let-flow](https://github.com/clj-commons/manifold/blob/master/doc/deferred.md#let-flow) operator. `aleph.http/wrap-ring-async-handler` helper can be used to covert async 3-arity Ring handler to Aleph-compliant one.
20
+
Aleph follows the [Ring](https://github.com/ring-clojure) spec fully, and can be a drop-in replacement for any existing Ring-compliant server. However, it also allows for the handler function to return a [Manifold deferred](https://github.com/clj-commons/manifold) to represent an eventual response. This feature may not play nicely with synchronous Ring middleware which modifies the response, but this can be easily fixed by reimplementing the middleware using Manifold's [let-flow](https://github.com/clj-commons/manifold/blob/master/doc/deferred.md#let-flow) operator. The `aleph.http/wrap-ring-async-handler` helper can be used to covert async 3-arity Ring handler to Aleph-compliant one.
16
21
17
-
```clj
22
+
```clojure
18
23
(require '[aleph.http :as http])
19
24
20
25
(defnhandler [req]
@@ -29,20 +34,20 @@ The body of the response may also be a Manifold stream, where each message from
29
34
30
35
For HTTP client requests, Aleph models itself after [clj-http](https://github.com/dakrone/clj-http), except that every request immediately returns a Manifold deferred representing the response.
31
36
32
-
```clj
37
+
```clojure
33
38
(require
34
39
'[manifold.deferred :as d]
35
40
'[byte-streams :as bs])
36
41
37
42
(-> @(http/get"https://google.com/")
38
-
:body
39
-
bs/to-string
40
-
prn)
43
+
:body
44
+
bs/to-string
45
+
prn)
41
46
42
47
(d/chain (http/get"https://google.com")
43
-
:body
44
-
bs/to-string
45
-
prn)
48
+
:body
49
+
bs/to-string
50
+
prn)
46
51
```
47
52
48
53
Aleph attempts to mimic the clj-http API and capabilities fully. It supports multipart/form-data requests, cookie stores, proxy servers and requests inspection with a few notable differences:
@@ -71,7 +76,7 @@ To learn more, [read the example code](http://aleph.io/examples/literate.html#al
71
76
72
77
On any HTTP request which has the proper `Upgrade` headers, you may call `(aleph.http/websocket-connection req)`, which returns a deferred which yields a **duplex stream**, which uses a single stream to represent bidirectional communication. Messages from the client can be received via `take!`, and sent to the client via `put!`. An echo WebSocket handler, then, would just consist of:
73
78
74
-
```clj
79
+
```clojure
75
80
(require '[manifold.stream :as s])
76
81
77
82
(defnecho-handler [req]
@@ -91,7 +96,7 @@ A TCP server is similar to an HTTP server, except that for each connection the h
91
96
92
97
An echo TCP server is very similar to the above WebSocket example:
93
98
94
-
```clj
99
+
```clojure
95
100
(require '[aleph.tcp :as tcp])
96
101
97
102
(defnecho-handler [s info]
@@ -108,7 +113,7 @@ To learn more, [read the example code](http://aleph.io/examples/literate.html#al
108
113
109
114
A UDP socket can be generated using `(aleph.udp/socket {:port 10001, :broadcast? false})`. If the `:port` is specified, it will yield a duplex socket which can be used to send and receive messages, which are structured as maps with the following data:
0 commit comments