Skip to content

Commit eeb453f

Browse files
committed
spec
1 parent 67e52ea commit eeb453f

File tree

5 files changed

+27
-42
lines changed

5 files changed

+27
-42
lines changed

README.md

+8-41
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,18 @@
11
# clj-web
22

33
- [part 1: basic web](doc/clj-web-from-the-ground-up-1.md)
4-
- [part 2: compojure](doc/clj-web-from-the-ground-up-2.md)
4+
- [part 2: routing with compojure](doc/clj-web-from-the-ground-up-2.md)
55
- [part 3: component & reloadable workflow](doc/clj-web-from-the-ground-up-3.md)
66
- [part 4: db](doc/clj-web-from-the-ground-up-4.md)
77
- [part 5: config](doc/clj-web-from-the-ground-up-5.md)
88
- [part 6: api](doc/clj-web-from-the-ground-up-6.md)
9-
- [part 7: logging](doc/clj-web-from-the-ground-up-7.md)
10-
- [part 8: test](doc/clj-web-from-the-ground-up-8.md)
9+
- [part 7: spec](doc/clj-web-from-the-ground-up-7.md)
10+
- [part 8: logging](doc/clj-web-from-the-ground-up-8.md)
11+
- [part 9: test](doc/clj-web-from-the-ground-up-9.md)
1112

12-
## Installation
13+
## Development
1314

14-
Download from http://example.com/FIXME.
15+
$ lein repl
16+
(init/start/stop/reset)
1517

16-
## Usage
17-
18-
FIXME: explanation
19-
20-
$ java -jar clj-web-0.1.0-standalone.jar [args]
21-
22-
## Options
23-
24-
FIXME: listing of options this app accepts.
25-
26-
## Examples
27-
28-
...
29-
30-
### Bugs
31-
32-
...
33-
34-
### Any Other Sections
35-
### That You Think
36-
### Might be Useful
37-
38-
## License
39-
40-
Copyright © 2019 FIXME
41-
42-
This program and the accompanying materials are made available under the
43-
terms of the Eclipse Public License 2.0 which is available at
44-
http://www.eclipse.org/legal/epl-2.0.
45-
46-
This Source Code may also be made available under the following Secondary
47-
Licenses when the conditions for such availability set forth in the Eclipse
48-
Public License, v. 2.0 are satisfied: GNU General Public License as published by
49-
the Free Software Foundation, either version 2 of the License, or (at your
50-
option) any later version, with the GNU Classpath Exception which is available
51-
at https://www.gnu.org/software/classpath/license.html.
18+
Access the app at http://localhost:3000/

src/clj_web/app.clj

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
(routes
1111
(GET "/" [] "Hello World!")
1212
(GET "/db" req (foo-handler/bar req db))
13+
(POST "/data" {:keys [body-params]} (foo-handler/data body-params))
1314
(route/not-found "404")))
1415

1516
(defrecord App [handler db]

src/clj_web/handler/foo.clj

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
(ns clj-web.handler.foo
22
(:require [clojure.tools.logging :as log]
33
[clj-web.db.foo :as foo-db]
4-
[ring.util.http-response :refer :all]))
4+
[ring.util.http-response :refer :all]
5+
[clojure.spec.alpha :as s]
6+
[clj-web.handler.spec :as hs]))
57

68
(defn bar [req db]
79
(log/debug req)
810
(ok (foo-db/bar db)))
11+
12+
(defn data [body]
13+
(if (s/valid? ::hs/data-request body)
14+
(ok (s/conform ::hs/data-request body))
15+
(bad-request (s/explain-str ::hs/data-request body))))

src/clj_web/handler/spec.clj

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(ns clj-web.handler.spec
2+
(:require [clojure.spec.alpha :as s]))
3+
4+
(s/def ::first-name string?)
5+
(s/def ::last-name string?)
6+
(s/def ::phone string?)
7+
8+
(s/def ::data-request
9+
(s/keys :req-un [::first-name ::last-name]
10+
:opt-un [::phone]))

0 commit comments

Comments
 (0)