vincentlowe

American Flights API (scaffold XML)

Sep 28th, 2021
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit="http://www.mulesoft.org/schema/mule/mule-apikit" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/mule-apikit http://www.mulesoft.org/schema/mule/mule-apikit/current/mule-apikit.xsd ">
  3. <apikit:config name="american-flights-api-config" api="american-flights-api.raml" outboundHeadersMapName="outboundHeaders" httpStatusVarName="httpStatus" />
  4. <flow name="american-flights-api-main">
  5. <http:listener config-ref="HTTP_Listener_config" path="/api/*">
  6. <http:response statusCode="#[vars.httpStatus default 200]">
  7. <http:headers>#[vars.outboundHeaders default {}]</http:headers>
  8. </http:response>
  9. <http:error-response statusCode="#[vars.httpStatus default 500]">
  10. <http:body>#[payload]</http:body>
  11. <http:headers>#[vars.outboundHeaders default {}]</http:headers>
  12. </http:error-response>
  13. </http:listener>
  14. <apikit:router config-ref="american-flights-api-config" />
  15. <error-handler>
  16. <on-error-propagate type="APIKIT:BAD_REQUEST">
  17. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  18. <ee:message>
  19. <ee:set-payload><![CDATA[%dw 2.0
  20. output application/json
  21. ---
  22. {message: "Bad request"}]]></ee:set-payload>
  23. </ee:message>
  24. <ee:variables>
  25. <ee:set-variable variableName="httpStatus">400</ee:set-variable>
  26. </ee:variables>
  27. </ee:transform>
  28. </on-error-propagate>
  29. <on-error-propagate type="APIKIT:NOT_FOUND">
  30. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  31. <ee:message>
  32. <ee:set-payload><![CDATA[%dw 2.0
  33. output application/json
  34. ---
  35. {message: "Resource not found"}]]></ee:set-payload>
  36. </ee:message>
  37. <ee:variables>
  38. <ee:set-variable variableName="httpStatus">404</ee:set-variable>
  39. </ee:variables>
  40. </ee:transform>
  41. </on-error-propagate>
  42. <on-error-propagate type="APIKIT:METHOD_NOT_ALLOWED">
  43. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  44. <ee:message>
  45. <ee:set-payload><![CDATA[%dw 2.0
  46. output application/json
  47. ---
  48. {message: "Method not allowed"}]]></ee:set-payload>
  49. </ee:message>
  50. <ee:variables>
  51. <ee:set-variable variableName="httpStatus">405</ee:set-variable>
  52. </ee:variables>
  53. </ee:transform>
  54. </on-error-propagate>
  55. <on-error-propagate type="APIKIT:NOT_ACCEPTABLE">
  56. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  57. <ee:message>
  58. <ee:set-payload><![CDATA[%dw 2.0
  59. output application/json
  60. ---
  61. {message: "Not acceptable"}]]></ee:set-payload>
  62. </ee:message>
  63. <ee:variables>
  64. <ee:set-variable variableName="httpStatus">406</ee:set-variable>
  65. </ee:variables>
  66. </ee:transform>
  67. </on-error-propagate>
  68. <on-error-propagate type="APIKIT:UNSUPPORTED_MEDIA_TYPE">
  69. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  70. <ee:message>
  71. <ee:set-payload><![CDATA[%dw 2.0
  72. output application/json
  73. ---
  74. {message: "Unsupported media type"}]]></ee:set-payload>
  75. </ee:message>
  76. <ee:variables>
  77. <ee:set-variable variableName="httpStatus">415</ee:set-variable>
  78. </ee:variables>
  79. </ee:transform>
  80. </on-error-propagate>
  81. <on-error-propagate type="APIKIT:NOT_IMPLEMENTED">
  82. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  83. <ee:message>
  84. <ee:set-payload><![CDATA[%dw 2.0
  85. output application/json
  86. ---
  87. {message: "Not Implemented"}]]></ee:set-payload>
  88. </ee:message>
  89. <ee:variables>
  90. <ee:set-variable variableName="httpStatus">501</ee:set-variable>
  91. </ee:variables>
  92. </ee:transform>
  93. </on-error-propagate>
  94. </error-handler>
  95. </flow>
  96. <flow name="american-flights-api-console">
  97. <http:listener config-ref="HTTP_Listener_config" path="/console/*">
  98. <http:response statusCode="#[vars.httpStatus default 200]">
  99. <http:headers>#[vars.outboundHeaders default {}]</http:headers>
  100. </http:response>
  101. <http:error-response statusCode="#[vars.httpStatus default 500]">
  102. <http:body>#[payload]</http:body>
  103. <http:headers>#[vars.outboundHeaders default {}]</http:headers>
  104. </http:error-response>
  105. </http:listener>
  106. <apikit:console config-ref="american-flights-api-config" />
  107. <error-handler>
  108. <on-error-propagate type="APIKIT:NOT_FOUND">
  109. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  110. <ee:message>
  111. <ee:set-payload><![CDATA[%dw 2.0
  112. output application/json
  113. ---
  114. {message: "Resource not found"}]]></ee:set-payload>
  115. </ee:message>
  116. <ee:variables>
  117. <ee:set-variable variableName="httpStatus">404</ee:set-variable>
  118. </ee:variables>
  119. </ee:transform>
  120. </on-error-propagate>
  121. </error-handler>
  122. </flow>
  123. <flow name="delete:\flights\(ID):american-flights-api-config">
  124. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core">
  125. <ee:variables>
  126. <ee:set-variable variableName="ID">attributes.uriParams.'ID'</ee:set-variable>
  127. </ee:variables>
  128. </ee:transform>
  129. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  130. <ee:message>
  131. <ee:set-payload><![CDATA[%dw 2.0
  132. output application/json
  133. ---
  134. {
  135. message: "Flight deleted (but not really)"
  136. }]]></ee:set-payload>
  137. </ee:message>
  138. </ee:transform>
  139. </flow>
  140. <flow name="get:\flights:american-flights-api-config">
  141. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  142. <ee:message>
  143. <ee:set-payload><![CDATA[%dw 2.0
  144. output application/json
  145. ---
  146. [
  147. {
  148. ID: 1,
  149. code: "ER38sd",
  150. price: 400,
  151. departureDate: "2017/07/26",
  152. origin: "CLE",
  153. destination: "SFO",
  154. emptySeats: 0,
  155. plane: {
  156. "type": "Boeing 737",
  157. totalSeats: 150
  158. }
  159. },
  160. {
  161. ID: 2,
  162. code: "ER45if",
  163. price: 540.99,
  164. departureDate: "2017/07/27",
  165. origin: "SFO",
  166. destination: "ORD",
  167. emptySeats: 54,
  168. plane: {
  169. "type": "Boeing 777",
  170. totalSeats: 300
  171. }
  172. }
  173. ]]]></ee:set-payload>
  174. </ee:message>
  175. </ee:transform>
  176. <flow-ref doc:name="getFlights" doc:id="542abc1a-c4af-4d69-b134-26f886bbe56b" name="getFlights"/>
  177. </flow>
  178. <flow name="get:\flights\(ID):american-flights-api-config">
  179. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core">
  180. <ee:variables>
  181. <ee:set-variable variableName="ID">attributes.uriParams.'ID'</ee:set-variable>
  182. </ee:variables>
  183. </ee:transform>
  184. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  185. <ee:message>
  186. <ee:set-payload><![CDATA[%dw 2.0
  187. output application/json
  188. ---
  189. {
  190. ID: 1,
  191. code: "ER38sd",
  192. price: 400,
  193. departureDate: "2017/07/26",
  194. origin: "CLE",
  195. destination: "SFO",
  196. emptySeats: 0,
  197. plane: {
  198. "type": "Boeing 737",
  199. totalSeats: 150
  200. }
  201. }]]></ee:set-payload>
  202. </ee:message>
  203. </ee:transform>
  204. <flow-ref doc:name="getFlightsByID" doc:id="7271f929-4d66-4cd6-9884-6dbf4751fa14" name="getFlightsByID"/>
  205. </flow>
  206. <flow name="post:\flights:application\json:american-flights-api-config">
  207. <ee:transform xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
  208. <ee:message>
  209. <ee:set-payload><![CDATA[%dw 2.0
  210. output application/json
  211. ---
  212. {
  213. staticmessage: "Flight record added (well, not so much)"
  214. }]]></ee:set-payload>
  215. </ee:message>
  216. </ee:transform>
  217. <flow-ref doc:name="postFlights" doc:id="d5e775dd-880b-48a2-bc76-a9b11acac9ae" name="postFlights"/>
  218. </flow>
  219. </mule>
  220.  
Advertisement
Add Comment
Please, Sign In to add comment