- The document discusses using Prismatic Schema and Swagger to describe, validate, and document Clojure web APIs. It covers topics like Schema validation and coercion, Ring-Swagger, Compojure-API, and Fnhouse-Swagger integration.
- Ring-Swagger implements the Swagger specification for Ring and uses Schema for data models and coercion. Compojure-API is an extendable web API library that uses Schema and generates Swagger documentation. Fnhouse-Swagger provides Swagger support for the Fnhouse library.
- The document encourages adopting Schema and Swagger tools to build robust and well-documented Clojure web APIs in a consistent manner across different frameworks.
9. Clojure Sausage?
A
Schema
is
a
Clojure(Script)
data
structure
describing
a
data
shape,
which
can
be
used
to
document
and
validate
func=ons
and
data.
h,ps://github.com/prismaAc/schema
17. perf
“For
now
our
pragmaAc
soluAon
is
to
only
turn
on
validaAon
at
key
boundaries
in
producAon
code
(using
:always-‐validate),
and
only
check
the
remaining
asserAons
in
tests.
In
pracAce
this
seems
to
catch
nearly
all
the
issues,
without
causing
any
performance
problems.”
-‐
Jason
Wolfe
27. Swagger
• a specification and complete framework implementation for
describing, producing, consuming, and visualizing RESTful web
services
– https://helloreverb.com/developers/swagger
• Existing adapters for most common web stacks
• Clojure Libs
– Octohipster (https://github.com/myfreeweb/octohipster)
– Swag (https://github.com/narkisr/swag)
– Ring-Swagger
• Compojure-Api (https://github.com/metosin/compojure-api)
• Fnhouse-swagger (https://github.com/metosin/fnhouse-swagger)
38. Ring-Swagger
• Swagger implementation for Ring
– https://github.com/metosin/ring-swagger
– Based on Schema for data models coercion
• Extendable mappings of Schemas to JSON Schemas
• Symmetric parsers for common types (inc. Dates, DateTimes)
• Add-ons (coercers, predicates, tools)
– Provides Swagger spec endpoints as Ring routes
• Resource-listing,Api-declarations, Swagger-UI
– Independent to routing-libs
• Currently bindings exist to Compojure-Api and fnHouse
47. Compojure-Api
• An extendable web api lib on top of Compojure
– https://github.com/metosin/compojure-api
– Macros middlewares with good defaults
– Schema-based models coercion
– Swagger docs
54. • Macro-fu to reverse-engineer the route tree at
macro-expansion time
– No runtime penalty
– Static routes (no ad-hoc hypermedia)
• Storing compiled route tree in
1) Evil Mutable State, part1: globally side-effecting macro
2) Evil Mutable State, part2: macro-filled global atom
3) Current: Namespace cluttering localVar
4) Next up: DynamicVar?
Route Resolution
61. fnhouse
• Fnhouse is a library that
builds on top of ring to
provide a concise way to
write web handlers safely,
readably, without global
variables, without repeating
yourself, and with hooks to
do much more.
• https://github.com/Prismatic/
fnhouse
62. fnhouse
• Defnks with metadata è annotated handler
– Builds on schema plumbing
• Bootstrap: collect defnks wrap to ring-
handlers
• No global state
66. Schema Swagger
• Prismatic Schema is an awesome tool
– Describe, validate coerce your data
• Swagger to publish out api descriptions
• Building on top of ring-swagger:
– Compojure-api è declarative web apis
– Fnhouse-swagger è meta-data done right
– YourFavouriteWebLib è just do it ( poke us).
67. Next things @ Metosin
• Ring-Swagger
– Make feature complete (+Swagger 2.0)
• Compojure-Api
– Cleanup route-peeling
– Ring-middleware-format
– Repl-tools?
• Help others to adapt
• kekkonen.io
– CQRS-lib