top

Package rata provides three things: Routes, a Router, and a RequestGenerator.

Routes are structs that define which Method and Path each associated http handler should respond to. Unlike many router implementations, the routes and the handlers are defined separately. This allows for the routes to be reused in multiple contexts. For example, a proxy server and a backend server can be created by having one set of Routes, but two sets of Handlers (one handler that proxies, another that serves the request). Likewise, your client code can use the routes with the RequestGenerator to create requests that use the same routes. Then, if the routes change, unit tests in the client and proxy service will warn you of the problem. This contract helps components stay in sync while relying less on integration tests.

For example, let's imagine that you want to implement a "pet" resource that allows you to view, create, update, and delete which pets people own. Also, you would like to include the owner_id and pet_id as part of the URL path.

First off, the routes might look like this:

petRoutes := rata.Routes{
  {Name: "get_pet",    Method: "GET",    Path: "/people/:owner_id/pets/:pet_id"},
  {Name: "create_pet", Method: "POST",   Path: "/people/:owner_id/pets"},
  {Name: "update_pet", Method: "PUT",    Path: "/people/:owner_id/pets/:pet_id"},
  {Name: "delete_pet", Method: "DELETE", Path: "/people/:owner_id/pets/:pet_id"},
}

On the server, create a matching set of http handlers, one for each route:

handlers := rata.Handlers{
  "get_pet":    newGetPetHandler(),
  "create_pet": newCreatePetHandler(),
  "update_pet": newUpdatePetHandler(),
  "delete_pet": newDeletePetHandler()
}

You can create a router by mixing the routes and handlers together:

router, err := rata.NewRouter(petRoutes, handlers)
if err != nil {
  panic(err)
}

The router is just an http.Handler, so it can be used to create a server in the usual fashion:

server := httptest.NewServer(router)

The handlers can obtain parameters derived from the URL path:

ownerId := rata.Param(request, "owner_id")

Meanwhile, on the client side, you can create a request generator:

requestGenerator := rata.NewRequestGenerator(server.URL, petRoutes)

You can use the request generator to ensure you are creating a valid request:

req, err := requestGenerator.CreateRequest("get_pet", rata.Params{"owner_id": "123", "pet_id": "5"}, nil)

The generated request can be used like any other http.Request object:

res, err := http.DefaultClient.Do(req)

Imported by 415 package(s)

  1. code.cloudfoundry.org/auction/simulation/repnode
  2. code.cloudfoundry.org/auctioneer
  3. code.cloudfoundry.org/auctioneer/handlers
  4. code.cloudfoundry.org/bbs
  5. code.cloudfoundry.org/bbs/handlers
  6. code.cloudfoundry.org/cc-uploader
  7. code.cloudfoundry.org/cc-uploader/handlers
  8. code.cloudfoundry.org/cli/api/cloudcontroller
  9. code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal
  10. code.cloudfoundry.org/cli/api/uaa
  11. code.cloudfoundry.org/cli/api/uaa/internal
  12. code.cloudfoundry.org/diego-ssh/healthcheck
  13. code.cloudfoundry.org/efsdriver/efsvoltools
  14. code.cloudfoundry.org/efsdriver/efsvoltools/voltoolshttp
  15. code.cloudfoundry.org/fileserver
  16. code.cloudfoundry.org/fileserver/handlers
  17. code.cloudfoundry.org/garden/client/connection
  18. code.cloudfoundry.org/garden/client/connection/connectionfakes
  19. code.cloudfoundry.org/garden/routes
  20. code.cloudfoundry.org/garden/server
  21. code.cloudfoundry.org/nsync
  22. code.cloudfoundry.org/nsync/handlers
  23. code.cloudfoundry.org/rep
  24. code.cloudfoundry.org/rep/cmd/rep
  25. code.cloudfoundry.org/rep/handlers
  26. code.cloudfoundry.org/routing-api
  27. code.cloudfoundry.org/routing-api/cmd/routing-api
  28. code.cloudfoundry.org/routing-api/handlers
  29. code.cloudfoundry.org/tps
  30. code.cloudfoundry.org/tps/handler
  31. code.cloudfoundry.org/voldriver
  32. code.cloudfoundry.org/voldriver/driverhttp
  33. code.cloudfoundry.org/volman
  34. code.cloudfoundry.org/volman/volhttp
  35. github.com/ArthurHlt/fly/commands
  36. github.com/DanLavine/bbs
  37. github.com/DanLavine/bbs/handlers
  38. github.com/FidelityInternational/atc
  39. github.com/FidelityInternational/atc/api
  40. github.com/FidelityInternational/atc/api/authserver
  41. github.com/FidelityInternational/atc/api/configserver
  42. github.com/FidelityInternational/atc/api/jobserver
  43. github.com/FidelityInternational/atc/api/pipes
  44. github.com/FidelityInternational/atc/api/present
  45. github.com/FidelityInternational/atc/api/resourceserver
  46. github.com/FidelityInternational/atc/api/resourceserver/versionserver
  47. github.com/FidelityInternational/atc/auth
  48. github.com/FidelityInternational/atc/auth/provider
  49. github.com/FidelityInternational/atc/mainredirect
  50. github.com/FidelityInternational/atc/web
  51. github.com/FidelityInternational/atc/worker
  52. github.com/FidelityInternational/atc/worker/transport
  53. github.com/FidelityInternational/atc/worker/transport/transportfakes
  54. github.com/FidelityInternational/atc/wrappa
  55. github.com/JamesClonk/atc
  56. github.com/TimSimmons/atc
  57. github.com/aashah/cli/api/cloudcontroller
  58. github.com/aashah/cli/api/uaa
  59. github.com/aashah/cli/api/uaa/internal
  60. github.com/amitkgupta/app-manager/start_message_builder
  61. github.com/amitkgupta/executor/api
  62. github.com/amitkgupta/executor/client
  63. github.com/amitkgupta/executor/server
  64. github.com/amitkgupta/inigo/helpers
  65. github.com/amitkgupta/rep
  66. github.com/amitkgupta/rep/api
  67. github.com/amitkgupta/rep/routes
  68. github.com/amitkgupta/rep/task_scheduler
  69. github.com/archSeer/atc
  70. github.com/bradylove/auctioneer
  71. github.com/bradylove/bbs
  72. github.com/bradylove/cli-plugin-repo
  73. github.com/cf-routing/bbs
  74. github.com/cf-routing/bbs/handlers
  75. github.com/cf-routing/lattice-app
  76. github.com/cf-routing/lattice-app/handlers
  77. github.com/cf-routing/lattice-app/routes
  78. github.com/cf-routing/nsync
  79. github.com/cf-routing/nsync/handlers
  80. github.com/chendrix/fly/commands
  81. github.com/chendrix/fly/commands/internal/hijacker
  82. github.com/chendrix/fly/commands/internal/setpipelinehelpers
  83. github.com/cloudfoundry-attic/receptor
  84. github.com/cloudfoundry-attic/receptor/handlers
  85. github.com/cloudfoundry-incubator/auction/simulation/repnode
  86. github.com/cloudfoundry-incubator/auctioneer
  87. github.com/cloudfoundry-incubator/auctioneer/handlers
  88. github.com/cloudfoundry-incubator/bbs
  89. github.com/cloudfoundry-incubator/bbs/handlers
  90. github.com/cloudfoundry-incubator/cc-uploader
  91. github.com/cloudfoundry-incubator/cc-uploader/handlers
  92. github.com/cloudfoundry-incubator/cf-mysql-benchmark-app/api
  93. github.com/cloudfoundry-incubator/cli-plugin-repo
  94. github.com/cloudfoundry-incubator/ducati-daemon/handlers
  95. github.com/cloudfoundry-incubator/efsdriver/efsvoltools
  96. github.com/cloudfoundry-incubator/efsdriver/efsvoltools/voltoolshttp
  97. github.com/cloudfoundry-incubator/file-server
  98. github.com/cloudfoundry-incubator/file-server/handlers
  99. github.com/cloudfoundry-incubator/galera-healthcheck/api
  100. github.com/cloudfoundry-incubator/garden/client/connection
  101. github.com/cloudfoundry-incubator/garden/client/connection/connectionfakes
  102. github.com/cloudfoundry-incubator/garden/client/connection/fakes
  103. github.com/cloudfoundry-incubator/garden/routes
  104. github.com/cloudfoundry-incubator/garden/server
  105. github.com/cloudfoundry-incubator/nsync
  106. github.com/cloudfoundry-incubator/nsync/handlers
  107. github.com/cloudfoundry-incubator/receptor
  108. github.com/cloudfoundry-incubator/receptor/handlers
  109. github.com/cloudfoundry-incubator/rep
  110. github.com/cloudfoundry-incubator/rep/cmd/rep
  111. github.com/cloudfoundry-incubator/rep/handlers
  112. github.com/cloudfoundry-incubator/routing-api
  113. github.com/cloudfoundry-incubator/routing-api/admin
  114. github.com/cloudfoundry-incubator/routing-api/cmd/routing-api
  115. github.com/cloudfoundry-incubator/routing-api/handlers
  116. github.com/cloudfoundry-incubator/stager
  117. github.com/cloudfoundry-incubator/stager/backend
  118. github.com/cloudfoundry-incubator/stager/handlers
  119. github.com/cloudfoundry-incubator/tps
  120. github.com/cloudfoundry-incubator/tps/handler
  121. github.com/cloudfoundry-incubator/veritas/lrps/submit_lrp
  122. github.com/cloudfoundry-incubator/voldriver
  123. github.com/cloudfoundry-incubator/voldriver/driverhttp
  124. github.com/cloudfoundry-incubator/volman
  125. github.com/cloudfoundry-incubator/volman/volhttp
  126. github.com/cloudfoundry-samples/lattice-app
  127. github.com/cloudfoundry-samples/lattice-app/handlers
  128. github.com/cloudfoundry-samples/lattice-app/routes
  129. github.com/cloudfoundry/auction/simulation/repnode
  130. github.com/cloudfoundry/auctioneer
  131. github.com/cloudfoundry/auctioneer/handlers
  132. github.com/cloudfoundry/bbs
  133. github.com/cloudfoundry/bbs/handlers
  134. github.com/cloudfoundry/cc-uploader
  135. github.com/cloudfoundry/cc-uploader/handlers
  136. github.com/cloudfoundry/cli-plugin-repo
  137. github.com/cloudfoundry/cli/api/cloudcontroller/ccv2
  138. github.com/cloudfoundry/cli/api/cloudcontroller/ccv2/internal
  139. github.com/cloudfoundry/cli/api/uaa
  140. github.com/cloudfoundry/cli/api/uaa/internal
  141. github.com/cloudfoundry/diego-ssh/healthcheck
  142. github.com/cloudfoundry/fileserver
  143. github.com/cloudfoundry/fileserver/handlers
  144. github.com/cloudfoundry/garden/client/connection
  145. github.com/cloudfoundry/garden/client/connection/connectionfakes
  146. github.com/cloudfoundry/garden/client/connection/fakes
  147. github.com/cloudfoundry/garden/routes
  148. github.com/cloudfoundry/garden/server
  149. github.com/cloudfoundry/go-ccapi/v3/client
  150. github.com/cloudfoundry/go-ccapi/v3/routing
  151. github.com/cloudfoundry/hm9000/actualstatelisteners
  152. github.com/cloudfoundry/hm9000/apiserver
  153. github.com/cloudfoundry/hm9000/apiserver/handlers
  154. github.com/cloudfoundry/nsync
  155. github.com/cloudfoundry/nsync/handlers
  156. github.com/cloudfoundry/rep
  157. github.com/cloudfoundry/rep/handlers
  158. github.com/cloudfoundry/stager
  159. github.com/cloudfoundry/stager/backend
  160. github.com/cloudfoundry/stager/handlers
  161. github.com/cloudfoundry/tps
  162. github.com/cloudfoundry/tps/handler
  163. github.com/cloudfoundry/voldriver
  164. github.com/cloudfoundry/voldriver/driverhttp
  165. github.com/concourse/atc
  166. github.com/concourse/atc/api
  167. github.com/concourse/atc/api/authserver
  168. github.com/concourse/atc/api/configserver
  169. github.com/concourse/atc/api/jobserver
  170. github.com/concourse/atc/api/pipes
  171. github.com/concourse/atc/api/present
  172. github.com/concourse/atc/api/resourceserver
  173. github.com/concourse/atc/api/resourceserver/versionserver
  174. github.com/concourse/atc/auth
  175. github.com/concourse/atc/auth/provider
  176. github.com/concourse/atc/mainredirect
  177. github.com/concourse/atc/web
  178. github.com/concourse/atc/web/authredirect
  179. github.com/concourse/atc/web/login
  180. github.com/concourse/atc/web/triggerbuild
  181. github.com/concourse/atc/web/webhandler
  182. github.com/concourse/atc/worker
  183. github.com/concourse/atc/worker/transport
  184. github.com/concourse/atc/worker/transport/transportfakes
  185. github.com/concourse/atc/wrappa
  186. github.com/concourse/baggageclaim
  187. github.com/concourse/baggageclaim/api
  188. github.com/concourse/baggageclaim/client
  189. github.com/concourse/fly/commands
  190. github.com/concourse/fly/commands/internal/hijacker
  191. github.com/concourse/fly/commands/internal/setpipelinehelpers
  192. github.com/concourse/gate
  193. github.com/concourse/glider/api
  194. github.com/concourse/glider/routes
  195. github.com/concourse/go-concourse/concourse
  196. github.com/concourse/go-concourse/concourse/internal
  197. github.com/concourse/tsa
  198. github.com/concourse/tsa/tsacmd
  199. github.com/concourse/turbine
  200. github.com/concourse/turbine/api
  201. github.com/contraband/checkin/api
  202. github.com/craigfurman/bbs
  203. github.com/cunnie/atc
  204. github.com/cunnie/atc/api
  205. github.com/cunnie/atc/api/authserver
  206. github.com/cunnie/atc/api/configserver
  207. github.com/cunnie/atc/api/jobserver
  208. github.com/cunnie/atc/api/pipes
  209. github.com/cunnie/atc/api/present
  210. github.com/cunnie/atc/api/resourceserver
  211. github.com/cunnie/atc/api/resourceserver/versionserver
  212. github.com/cunnie/atc/auth
  213. github.com/cunnie/atc/auth/provider
  214. github.com/cunnie/atc/web
  215. github.com/cunnie/atc/web/login
  216. github.com/cunnie/atc/web/triggerbuild
  217. github.com/cunnie/atc/web/webhandler
  218. github.com/cunnie/atc/wrappa
  219. github.com/danhigham/bbs
  220. github.com/danhigham/bbs/handlers
  221. github.com/danlavine/bbs
  222. github.com/danlavine/bbs/handlers
  223. github.com/digitalocean/atc
  224. github.com/dolph/concourse-atc
  225. github.com/ebabani/atc
  226. github.com/evanphx/atc
  227. github.com/farcaller/atc
  228. github.com/geofffranks/fly/commands
  229. github.com/glyn/cli-plugin-repo
  230. github.com/hpcloud/lattice-app
  231. github.com/hpcloud/lattice-app/handlers
  232. github.com/hpcloud/lattice-app/routes
  233. github.com/ibmjstart/cli-plugin-repo
  234. github.com/jadekler/atc
  235. github.com/jadekler/atc/api
  236. github.com/jadekler/atc/auth
  237. github.com/jadekler/atc/mainredirect
  238. github.com/jadekler/atc/web
  239. github.com/jadekler/atc/worker
  240. github.com/jadekler/atc/wrappa
  241. github.com/jadekler/fly/commands
  242. github.com/jasonkeene/atc
  243. github.com/jasonkeene/cli-plugin-repo
  244. github.com/jberkhahn/hm9000/apiserver
  245. github.com/jberkhahn/hm9000/apiserver/handlers
  246. github.com/jfmyers9/bbs
  247. github.com/jfmyers9/gotta-track-em-all/handlers
  248. github.com/jfmyers9/gotta-track-em-all/routes
  249. github.com/jghiloni/atc
  250. github.com/jghiloni/cli-plugin-repo
  251. github.com/julz/garden/client/connection
  252. github.com/julz/garden/routes
  253. github.com/julz/garden/server
  254. github.com/krujos/cli-plugin-repo
  255. github.com/layer-x/pluggable-auction/simulation/repnode
  256. github.com/layer-x/pluggable-auctioneer
  257. github.com/layer-x/pluggable-auctioneer/handlers
  258. github.com/layer-x/pluggable-bbs
  259. github.com/layer-x/pluggable-bbs/handlers
  260. github.com/layer-x/pluggable-rep
  261. github.com/layer-x/pluggable-rep/handlers
  262. github.com/luan/teapot
  263. github.com/luan/teapot/handlers
  264. github.com/mfine30/kyx/router
  265. github.com/micahyoung/garden/routes
  266. github.com/micahyoung/garden/server
  267. github.com/mmb/atc
  268. github.com/mmb/atc/api
  269. github.com/mmb/atc/api/authserver
  270. github.com/mmb/atc/api/configserver
  271. github.com/mmb/atc/api/jobserver
  272. github.com/mmb/atc/api/pipes
  273. github.com/mmb/atc/api/present
  274. github.com/mmb/atc/api/resourceserver
  275. github.com/mmb/atc/api/resourceserver/versionserver
  276. github.com/mmb/atc/auth
  277. github.com/mmb/atc/auth/provider
  278. github.com/mmb/atc/mainredirect
  279. github.com/mmb/atc/web
  280. github.com/mmb/atc/web/authredirect
  281. github.com/mmb/atc/web/login
  282. github.com/mmb/atc/web/webhandler
  283. github.com/mmb/atc/worker
  284. github.com/mmb/atc/worker/transport
  285. github.com/mmb/atc/worker/transport/transportfakes
  286. github.com/mmb/atc/wrappa
  287. github.com/nelsam/atc
  288. github.com/onsi/grace
  289. github.com/onsi/grace/handlers
  290. github.com/onsi/grace/routes
  291. github.com/oppegard/atc
  292. github.com/oppegard/atc/api
  293. github.com/oppegard/atc/auth
  294. github.com/oppegard/atc/web
  295. github.com/oppegard/atc/wrappa
  296. github.com/phillbaker/atc
  297. github.com/pivotal-cf-experimental/garden/client/connection
  298. github.com/pivotal-cf-experimental/garden/client/connection/connectionfakes
  299. github.com/pivotal-cf-experimental/garden/routes
  300. github.com/pivotal-cf-experimental/garden/server
  301. github.com/rfliam/atc
  302. github.com/robdimsdale/atc
  303. github.com/robdimsdale/atc/api
  304. github.com/robdimsdale/atc/api/configserver
  305. github.com/robdimsdale/atc/api/jobserver
  306. github.com/robdimsdale/atc/api/pipes
  307. github.com/robdimsdale/atc/api/present
  308. github.com/robdimsdale/atc/api/resourceserver
  309. github.com/robdimsdale/atc/web
  310. github.com/robdimsdale/atc/web/routes
  311. github.com/robdimsdale/atc/web/triggerbuild
  312. github.com/robdimsdale/fly/commands
  313. github.com/rosenhouse/cnsim
  314. github.com/s-matyukevich/garden/client/connection
  315. github.com/s-matyukevich/garden/client/connection/fakes
  316. github.com/s-matyukevich/garden/routes
  317. github.com/s-matyukevich/garden/server
  318. github.com/s-matyukevich/go-ccapi/v3/client
  319. github.com/s-matyukevich/go-ccapi/v3/routing
  320. github.com/savaki/atc
  321. github.com/savaki/atc/api
  322. github.com/savaki/atc/api/configserver
  323. github.com/savaki/atc/api/jobserver
  324. github.com/savaki/atc/api/pipes
  325. github.com/savaki/atc/api/present
  326. github.com/savaki/atc/api/resourceserver
  327. github.com/savaki/atc/web
  328. github.com/savaki/atc/web/routes
  329. github.com/savaki/atc/web/triggerbuild
  330. github.com/sclevine/cli-plugin-repo
  331. github.com/seadowg/fly/commands
  332. github.com/shashidharatd/garden/client/connection
  333. github.com/shashidharatd/garden/routes
  334. github.com/shashidharatd/garden/server
  335. github.com/shashidharatd/receptor
  336. github.com/shashidharatd/receptor/handlers
  337. github.com/shashidharatd/receptor/task_handler
  338. github.com/shinji62/atc
  339. github.com/shinji62/atc/api
  340. github.com/shinji62/atc/api/authserver
  341. github.com/shinji62/atc/api/configserver
  342. github.com/shinji62/atc/api/jobserver
  343. github.com/shinji62/atc/api/pipes
  344. github.com/shinji62/atc/api/present
  345. github.com/shinji62/atc/api/resourceserver
  346. github.com/shinji62/atc/api/resourceserver/versionserver
  347. github.com/shinji62/atc/auth
  348. github.com/shinji62/atc/auth/provider
  349. github.com/shinji62/atc/web
  350. github.com/shinji62/atc/web/authredirect
  351. github.com/shinji62/atc/web/basicauth
  352. github.com/shinji62/atc/web/login
  353. github.com/shinji62/atc/web/triggerbuild
  354. github.com/shinji62/atc/web/webhandler
  355. github.com/shinji62/atc/worker
  356. github.com/shinji62/atc/worker/transport
  357. github.com/shinji62/atc/worker/transport/transportfakes
  358. github.com/shinji62/atc/wrappa
  359. github.com/simonleung8/cli-plugin-repo
  360. github.com/stepanstipl/atc
  361. github.com/stormdock/garden/routes
  362. github.com/stormdock/garden/server
  363. github.com/sykesm/ducati-daemon/handlers
  364. github.com/sykesm/nsync
  365. github.com/takeyourhatoff/atc
  366. github.com/tedsuo/diegito
  367. github.com/voelzmo/hm9000/apiserver
  368. github.com/voelzmo/hm9000/apiserver/handlers
  369. github.com/wfernandes/atc
  370. github.com/wfernandes/cli-plugin-repo
  371. github.com/xoebus/checkin/api
  372. github.com/yanana/atc
  373. github.com/yanana/atc/api
  374. github.com/yanana/atc/api/authserver
  375. github.com/yanana/atc/api/configserver
  376. github.com/yanana/atc/api/jobserver
  377. github.com/yanana/atc/api/pipes
  378. github.com/yanana/atc/api/present
  379. github.com/yanana/atc/api/resourceserver
  380. github.com/yanana/atc/api/resourceserver/versionserver
  381. github.com/yanana/atc/auth
  382. github.com/yanana/atc/auth/provider
  383. github.com/yanana/atc/web
  384. github.com/yanana/atc/web/login
  385. github.com/yanana/atc/web/triggerbuild
  386. github.com/yanana/atc/web/webhandler
  387. github.com/yanana/atc/wrappa
  388. github.com/zabawaba99/atc
  389. github.com/zabawaba99/atc/api
  390. github.com/zabawaba99/atc/auth
  391. github.com/zabawaba99/atc/mainredirect
  392. github.com/zabawaba99/atc/web
  393. github.com/zabawaba99/atc/worker
  394. github.com/zabawaba99/atc/wrappa
  395. github.com/zabawaba99/fly/commands
  396. github.com/zachgersh/atc
  397. github.com/zachgersh/atc/api
  398. github.com/zachgersh/atc/api/authserver
  399. github.com/zachgersh/atc/api/configserver
  400. github.com/zachgersh/atc/api/jobserver
  401. github.com/zachgersh/atc/api/pipes
  402. github.com/zachgersh/atc/api/present
  403. github.com/zachgersh/atc/api/resourceserver
  404. github.com/zachgersh/atc/api/resourceserver/versionserver
  405. github.com/zachgersh/atc/auth
  406. github.com/zachgersh/atc/auth/provider
  407. github.com/zachgersh/atc/web
  408. github.com/zachgersh/atc/web/login
  409. github.com/zachgersh/atc/web/triggerbuild
  410. github.com/zachgersh/atc/web/webhandler
  411. github.com/zachgersh/atc/wrappa
  412. github.com/zachgersh/fly/commands
  413. github.com/zachgersh/go-concourse/concourse
  414. github.com/zachgersh/go-concourse/concourse/internal
  415. github.com/zankich/fly/commands

Imported only in test by 4 package(s)

  1. github.com/cf-guardian/rata
  2. github.com/cloudfoundry-attic/receptor/cmd/receptor
  3. github.com/cloudfoundry-incubator/receptor/cmd/receptor
  4. github.com/concourse/atc/api/auth

Imports 1 package(s)

  1. github.com/bmizerany/pat

Test imports 3 package(s)

  1. github.com/onsi/ginkgo
  2. github.com/onsi/gomega
  3. github.com/onsi/gomega/ghttp