Microservices with Clojure: Develop event-driven, scalable, and reactive microservices with real-time monitoring by Anuj Kumar

Microservices with Clojure: Develop event-driven, scalable, and reactive microservices with real-time monitoring by Anuj Kumar

Author:Anuj Kumar [Kumar, Anuj]
Language: eng
Format: epub
Tags: COM060180 - COMPUTERS / Web / Web Services and APIs, COM051000 - COMPUTERS / Programming / General, COM051280 - COMPUTERS / Programming Languages / Java
Publisher: Packt Publishing
Published: 2018-01-25T00:00:00+00:00


(def auth

{:name ::auth

:enter

(fn [context]

(let [token (-> context :request :headers (get "token"))]

(if-let [uid (and (not (nil? token)) (get-uid token))]

(assoc-in context [:request :tx-data :user] uid)

(chain/terminate

(assoc context

:response {:status 401

:body "Auth token not found"})))))

:error

(fn [context ex-info]

(assoc context

:response {:status 500

:body (.getMessage ex-info)}))})

;; Tabular routes

(def routes #{["/" :get (conj common-interceptors `auth `home-page)]})

As of now, for simplicity, let's assume that the get-uid function just returns a response with uid as a field that has a fixed value, hhuser, that can be picked by interceptors, such as home-page, to construct the response further down the interceptor chain:

(ns helping-hands.service

(:require [cheshire.core :as jp]

[io.pedestal.http :as http]

[io.pedestal.http.route :as route]

[io.pedestal.http.body-params :as body-params]

[io.pedestal.interceptor.chain :as chain]

[ring.util.response :as ring-resp]))



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.