Routing

Jets translates your routes.rb file into API Gateway resources, and connects them to your Lambda functions:

config/routes.rb:

Jets.application.routes.draw do
  get  "posts", to: "posts#index"
  get  "posts/new", to: "posts#new"
  get  "posts/:id", to: "posts#show"
  post "posts", to: "posts#create"
  get  "posts/:id/edit", to: "posts#edit"
  put  "posts", to: "posts#update"
  delete  "posts", to: "posts#delete"

  resources :comments # expands to the RESTful routes above

  any "posts/hot", to: "posts#hot" # GET, POST, PUT, etc request all work
end

You can check your routes in the API Gateway console:

Screenshot of generated API Gateway resources in the AWS Console

You can get your API Gateway endpoints from the API Gateway console, and test them with curl or postman. Example:

$ curl -s "https://quabepiu80.execute-api.us-east-1.amazonaws.com/dev/posts" | jq .
{
  "hello": "world",
  "action": "index"
}

jets routes

Run the jets routes cli command to get a list of your routes.

$ jets routes
+--------+----------------+--------------------+
|  Verb  |      Path      | Controller#action  |
+--------+----------------+--------------------+
| GET    | posts          | posts#index        |
| GET    | posts/new      | posts#new          |
| GET    | posts/:id      | posts#show         |
| POST   | posts          | posts#create       |
| GET    | posts/:id/edit | posts#edit         |
| PUT    | posts/:id      | posts#update       |
| DELETE | posts/:id      | posts#delete       |
| ANY    | *catchall      | jets/public#show   |
+--------+----------------+--------------------+
$

Routing Guide

There is more information about the Jets Router in the Routing Guide docs.

Production Deployment

Important: If you are deploying a production service, it is strongly recommended to use a Custom Domain. Jets computes and figures out whether or not it needs to replace the REST API as part of deployment. When the REST API is replaced, the API Endpoint will be different. By using Custom Domain, you’ll be able to keep the same endpoint.

Pro tip: Use the <- and -> arrow keys to move back and forward.

Edit this page

See a typo or an error? You can improve this page. This website is available on GitHub, and contributions are encouraged and welcomed. We love pull requests from you!