Skip to content

Commit

Permalink
spec
Browse files Browse the repository at this point in the history
  • Loading branch information
quan-nh committed Mar 9, 2022
1 parent 67e52ea commit eeb453f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 42 deletions.
49 changes: 8 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,18 @@
# clj-web

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

## Installation
## Development

Download from http://example.com/FIXME.
$ lein repl
(init/start/stop/reset)

## Usage

FIXME: explanation

$ java -jar clj-web-0.1.0-standalone.jar [args]

## Options

FIXME: listing of options this app accepts.

## Examples

...

### Bugs

...

### Any Other Sections
### That You Think
### Might be Useful

## License

Copyright © 2019 FIXME

This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0.

This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License, v. 2.0 are satisfied: GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or (at your
option) any later version, with the GNU Classpath Exception which is available
at https://www.gnu.org/software/classpath/license.html.
Access the app at http://localhost:3000/
File renamed without changes.
1 change: 1 addition & 0 deletions src/clj_web/app.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
(routes
(GET "/" [] "Hello World!")
(GET "/db" req (foo-handler/bar req db))
(POST "/data" {:keys [body-params]} (foo-handler/data body-params))
(route/not-found "404")))

(defrecord App [handler db]
Expand Down
9 changes: 8 additions & 1 deletion src/clj_web/handler/foo.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
(ns clj-web.handler.foo
(:require [clojure.tools.logging :as log]
[clj-web.db.foo :as foo-db]
[ring.util.http-response :refer :all]))
[ring.util.http-response :refer :all]
[clojure.spec.alpha :as s]
[clj-web.handler.spec :as hs]))

(defn bar [req db]
(log/debug req)
(ok (foo-db/bar db)))

(defn data [body]
(if (s/valid? ::hs/data-request body)
(ok (s/conform ::hs/data-request body))
(bad-request (s/explain-str ::hs/data-request body))))
10 changes: 10 additions & 0 deletions src/clj_web/handler/spec.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns clj-web.handler.spec
(:require [clojure.spec.alpha :as s]))

(s/def ::first-name string?)
(s/def ::last-name string?)
(s/def ::phone string?)

(s/def ::data-request
(s/keys :req-un [::first-name ::last-name]
:opt-un [::phone]))

0 comments on commit eeb453f

Please sign in to comment.