Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Clojure.specを活用したコード・ファーストスタイルのRESTサービス開発
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kenji Nakamura
October 05, 2017
Technology
760
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Clojure.specを活用したコード・ファーストスタイルのRESTサービス開発
(増席) 教養としてのClojure - そろそろ学んでおきたい2017年秋
https://d-cube.connpass.com/event/67567/presentation/
Kenji Nakamura
October 05, 2017
Other Decks in Technology
See All in Technology
AIエージェントを安全で速い現場監督にする:Jev・Obsidian・メタハーネス
x5gtrn
PRO
0
120
Argo CDとAtlantisで実現するインフラ管理のセルフサービス化──小規模SREチームで支えるプラットフォーム
cassius7
0
150
AI感のないAWS構成図をAIエージェントに描かせたい!
sagochiko
1
370
音声コミュニティを守るAI監視基盤_ 90%以上の入力削減を支えたServerless設計と運用判断
shuheioka123
0
110
Goodbye ShellScript, Hello File-based App
shunsock
0
1.1k
「ピッケル本」日本語版は4.0(第6版)が出版されるべき / pickaxe4-nagoyark05
kakutani
2
300
C#未経験の僕がAIに読めるコードを書かせるまで
maguroalternative
0
300
GitHub Agentic Workflows を触ってみる
htkym
2
590
AIに任せた品質は、誰が見立てるのか - AI時代のテストマネジメント
nakanao
3
3.1k
作って終わりじゃないサーバーレス 〜9年運用する大規模EC物流API基盤の設計・運用のリアル〜
zozotech
PRO
0
530
負債のメタファと2026年 / Debt Metaphor in Agentic Engineering Age 202609 Edition
twada
PRO
12
7.3k
エージェントはローカル、検証はMicroVM — Lambda MicroVMsでつくるServerless CI
fujioka6789
3
790
Featured
See All Featured
Docker and Python
trallard
47
4.2k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
58k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.9k
Skip the Path - Find Your Career Trail
mkilby
1
240
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
680
Designing Experiences People Love
moore
143
24k
How to build a perfect <img>
jonoalderson
1
6k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1k
Transcript
を活用したコード・ファーストスタ を活用したコード・ファーストスタ イルの イルの サービス開発 サービス開発 - D3 Meetup 教養としてのClojure
2017/10/4 - 株式会社シグニファイア 代表 中村研二
自己紹介 自己紹介 年間米国の金融・通信系スタートアップでエンジニア・マネー ジャ・ディレクターをしていました。 年から開発は 。ミッションクリティカルシステ ムにも使用しました。 昨年 の開発に特化した、株式会社シグニファ イアを設立。
紹介したいこと 紹介したいこと コードと デザインの乖離を無くし、メンテナンスコストを最 小に抑える の動的言語を活用したクイック・ターンアラウンドな開 発サイクル の活用例 質問・ディスカッションは で!
の文法解説 の詳細な使い方 の詳細
って って 型がないから心配 で静的型付き言語とは違ったアプローチでエラー チェック 起動が遅くて 駆動開発 によるホットリロー ディング カッコが多くて読み書きしづらそう
モードを使えばカッコを気にせずコーディングでき る!
フレームワーク フレームワーク ビルドツール 対話開発環境 サーバ抽象化フレームワーク 上で動作するルーティングライブラリ 上で 用の機能を追加したライ ブラリ
フレームワーク フレームワーク を定義する スペックに準拠し、設計、 ドキュメントなどをサポートするツール群 データ構造を定義し、バリデーションなどを行うラ イブラリ に や ス
キーマ、 サポート機能を付加するライブラリ サーバーを起動することなく 上のロジックをテスト することができるライブラリ
プロジェクトの生成と設定 プロジェクトの生成と設定 は をサポート、 はまだ 依存だが で 対応予定) lein new
compojure-api-with-spec
None
(defproject compojure-api-with-spec "0.1.0-SNAPSHOT" :description "compojure-api v2 and clojure.spec demo" :url
"https://github.com/k2n/compojure-api-with-spec" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[clj-time "0.14.0"] [metosin/compojure-api "2.0.0-alpha7"] [metosin/spec-tools "0.3.2"] [org.clojure/clojure "1.9.0-beta1"]] :ring {:handler compojure-api-with-spec.handler/app :async? true :nrepl {:start? true}} :uberjar-name "server.jar" :profiles {:dev {:dependencies [[peridot "0.5.0"]] :plugins [[lein-ring "0.12.0"] [com.jakemccrary/lein-test-refresh "0.21.1"]] :global-vars {*warn-on-reflection* true}}})
None
(ns compojure-api-with-spec.handler (:require [compojure.api.sweet :refer [api]] [compojure-api-with-spec [spec-coercion-routes :refer [spec-coercion-routes]]
[spec-validation-routes :refer [spec-validation-routes]]])) (def app (api {:swagger {:ui "/" :spec "/swagger.json" :data {:info {:title "Clojureでコード・ファーストなSwagger駆動REST API"} :tags [{:name "validation" :description "clojure.specによるバリデーション"} {:name "coercion" :description "clojure.specでコアーション"}]}}} spec-validation-routes spec-coercion-routes))
None
(ns compojure-api-with-spec.spec-validation-routes (:require [compojure.api.sweet :refer [context GET POST]] [ring.util.http-response :refer
[ok]] [clojure.spec.alpha :as s] [spec-tools.spec :as spec])) (def email-regex #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$") (def max-age 140) (s/def ::greeting (assoc spec/string? :description "このように注釈を定義することができる")) (s/def ::comment (assoc spec/string? :description "年齢の偶奇数を判定します")) (s/def ::response (s/keys :req-un [::greeting ::comment])) (s/def ::email (s/and spec/string? #(re-matches email-regex %))) (s/def ::age (s/and spec/int? #(> max-age %) #((complement neg?) %))) (defn validation-handler [email-address current-age] {:pre [(s/valid? ::email email-address) (s/valid? ::age current-age)] :post [(s/valid? ::response %)]} {:greeting (str email-address "を登録しました!") :comment (if (even? current-age) "あなたの年齢は偶数です"
None
(ns compojure-api-with-spec.spec-coercion-routes (:require [compojure.api.sweet :refer [context GET POST]] [compojure.api.coercion.spec :as
spec-coercion] [ring.util.http-response :refer [ok]] [clojure.spec.alpha :as s] [spec-tools.conform :as conform] [spec-tools.core :as st] [spec-tools.spec :as spec])) (s/def ::name spec/string?) (s/def ::amount (assoc spec/bigdec? :json-schema/type "string" :description "整数または小数を文字列として入力")) (s/def ::amount-type spec/string?) (defn string->bigdec [_ x] (cond (bigdec? x) x (string? x) (try (java.math.BigDecimal. x) (catch NumberFormatException e ::s/invalid)) :else ::s/invalid)) (def string-conforming (st/type-conforming
None
(ns compojure-api-with-spec.spec-routes-test (:require [clojure.test :refer :all] [clojure.edn :as edn] [cheshire.core
:as json] [compojure-api-with-spec.handler :refer [app]] [peridot.core :refer :all])) (deftest spec-routes-test (testing "validation" (testing "get" (testing "valid email address" (is (= 200 (-> (session app) (request "/
[email protected]
") :response :status)))) (testing "email address without domain" (is (= 400 (-> (session app) (request "/validation?email-address=foo") :response :status)))) (testing "email address without TLD" (is (= 400 (-> (session app) (request "/validation?email-address=foo@example") :response :status)))) (testing "email address with 1 character TLD, which is invalid."
終わりに 終わりに 今回の例はマクロを多用した 的な使われ方。通常はこれほど マジカルではない。 と はまだα版 の統合 への適用 を導入したくなったらお声がけください!コンサル・開
発承ります。