Server-side API'sλ︎
APIs are an excellent way to make a service accessible to the wider world.
Server-side apis in Clojure can be self-documenting (OpenAPI), highly efficient and a joy to develop.
The ring specification abstracts HTTP requests & responses, automatically converting to and from Clojure hash-maps which are far simpler and effecitive to work with.
Clojure routing libraries typically take either use a data configuration or provide a Domain Specific Language (DSL) for defining routes.
Practicalli recommends Reitit
There are many excellent routing libraries available for Clojure, however reitit is very well documented and takes a data centric approach.
Practicalli has found reitit very easy to work with on new project and to migrate existing project.
Reititλ︎
Reitit is a data defined routing library which can be used with the Ring specification and middleware.
Route configuration is pre-compiled, so if highly efficient. Routing is also bi-directional. Defining route configuration as data simplifies validation, with errors returned containing clojure.spec information.
- define routes as data (validated with clojure.spec)
- ring support
- middleware support
- data coercion
- validation (clojure.spec or Malli)
- swagger (openapi) documentation with custom templates
Compojureλ︎
compojure
library provides the defroutes
macro and HTTP methods (GET, POST, etc) as a DSL for defining routes.
compojure-apiλ︎
Compojure API library and template provide a quick way to create an API, by extending Compojure features.
Prismatic schemaλ︎
Schema validation defines the shape of any data that the API will respond with as well as any data that is sent along with a request.
Self-documenting with Swaggerλ︎
This template contains Swagger that documents the API's you are creating and ring-swagger constructs the documentation as you create your code.
Referencesλ︎
- Getting started with Compojure API
ring-swagger
- RESTful CRUD APIs Using Compojure-API and Toucan - part1
- RESTful CRUD APIs Using Compojure-API and Toucan - part2