美文网首页
swagger1st和friboo

swagger1st和friboo

作者: 红尘赌客 | 来源:发表于2015-11-14 18:10 被阅读59次

swagger1st

swagger1st库提供了符合Ring规范的handler,能够根据Swagger定义解析、验证、路由HTTP请求。

使用swagger1st,不是在代码中定义API,而是利用Swagger官方的编辑器根据Swagger 2.0规范定义API。这样产生了一种API优先的开发流程,并且是使用独立于任何开发语言的方式定义API。

friboo

friboo提供了一些component,用于辅助Clojure的微服务应用开发。friboo鼓励采用swagger1st实行API优先的开发方式。

HTTP component

使用def-http-component宏创建HTTP component。http组件启动时,内部调用swagger1st创建handler,并使用jetty适配器运行之。

(ns myapi
  (:require [org.zalando.stups.friboo.system.http :refer [def-http-component]))

(def-http-component MyAPI "my-api.yaml" [db scheduler])

(defn my-api-function [parameters request db scheduler]
  ; 这里能够使用依赖的db和scheduler组件
  )

上面的代码创建了MyAPI组件,依赖于db和scheduler组件。my-api-function函数的第一个参数是一个扁平的map,对应的Swagger规范的parameters。

http组件使用:configuration存放配置项,在启动组件时用到它,例如

(map->MyAPI {:configuration {:port        8080
                             :cors-origin "*.zalando.de"}})

推荐采用下面的方式创建一个http系统。

(ns my-app.core
  (:require [org.zalando.stups.friboo.config :as config]
            [org.zalando.stups.friboo.system :as system]))

(defn run
  [default-configuration]
  (let [configuration (config/load-configuration
                        (system/default-http-namespaces-and :db)
                        [my-app.sql/default-db-configuration
                         my-app.api/default-http-configuration
                         default-configuration])
        system (system/http-system-map configuration
                                       my-app.api/map->API [:db]
                                       :db (my-app.sql/map->DB {:configuration (:db configuration)}))]

    (system/run configuration system)))

DB component

使用def-db-component宏创建。DB组件本质上是一个兼容db-spec的数据结构,使用:datasource存放数据源。

(ns mydb
  (:require [org.zalando.stups.friboo.system.db :refer [def-db-component]))

(def-db-component MyDB)

与http组件类似,db组件使用:configuration存放配置项,在启动组件时用到。

(map->MyDB {:configuration {:subprotocol "postgresql"
                            :subname     "localhost/mydb"}})

相关文章

  • swagger1st和friboo

    swagger1st swagger1st库提供了符合Ring规范的handler,能够根据Swagger定义解析...

  • -和 和 -

    产品介绍:和和是一款会员制共享平台;所有 经营者可在APP内注册和和商家成为会员供 应商(实体店、网店、微商、平台...

  • &和&&,|和||

    原文:https://blog.csdn.net/chinabestchina/article/details/7...

  • 和可和,非常和

    我年纪很小的时候,父亲有一本笔记本,上面只写了一句话:万物并育而不相害,道并行而不相悖。我当时很喜欢这句话,所以期...

  • kotlin中的空? 和 ?. 和 ?: 和 as? 和 !!

    ? 可空类型 kotlin和Java的类型系统之间的一个很重要的区别就是,Kotlin对可空类型的显示支持 也就是...

  • self. 和 _ 和 = 和 set

    声明了一个属性 @property (a,b) p1; 只有用self.调用时修饰关键词才起作用, 用_调用...

  • Observable和Observe和Subcriblers 和

    Observable事件源,被观察者。Subcriblers 观察者,事件订阅者Observer 同Subcrib...

  • ?. 和 ?: 和 let 和 with和 解构声明 使用说明

  • 房子和粮食和蔬菜和大海

    我有一间房子,面朝房子,房子和房子和房子的后面是群山。我有一盏粉红色的落地灯,商品详情页写的是茱萸粉,与百度首页的...

  • nil和NSNull和NULL和Nil

    一、nil 我们给对象赋值时一般会使用object = nil,表示我想把这个对象释放掉; 或者对象由于某种原因,...

网友评论

      本文标题:swagger1st和friboo

      本文链接:https://www.haomeiwen.com/subject/nqlkhttx.html