A REST API which serves endpoints to create users, products and orders for a simple commerce. A swagger documentation is available here.
GET /users
GET /users/:uid
POST /users
PUT /users/:uid
DELETE /users/:uid
GET /products
GET /products/:productid
POST /products
PUT /products/:productid
DELETE /products/:productid
GET /orders
GET /orders/:orderId
POST /orders
PUT /orders/:orderId
DELETE /orders/:orderId
SQLite is used as database. next.jdbc is used for JDBC-based access to the database.
ring is used as web server.
compojure is used as routing library.
hugsql is used to define database functions from sql queries for creating a clean separation of Clojure and SQL code.
data.json is used for generating JSON response.
A next.jdbc.plan is used to reduce a join query.
A next.jdbc.with-transaction macro is used to warranty a correct order creation which requires insertion into two tables: orders and orders_products.
- connection.clj: connection and datasource for sqlite database
- handler.clj: project entry point
- middlewares.clj: web server middlewares
- orders.clj: functions to handle orders endpoints
- products.clj: function to handle products endpoints
- routes.clj: API routes
- users.clj: functions to handle users endpoints
- utils.clj: some common functions
- sql/orders.clj: function to reduce join query between orders and orders_products table.
- sql/orders.sql: orders table queries
- sql/products.sql: products table queries
- sql/users.sql: users table queries
You will need Leiningen 2.0.0 or above installed.
To start a web server for the application, run:
lein ring server
Copyright © 2022 FIXME