1. Introduction

2. Resources

Jets routing leverages a REST architecture design by default. A key component of a REST are resources. With HTTP, we can take actions like GET, POST, PUT, PATCH, DELETE on resources. Jets uses HTTP verbs and RESTful resources to achieve the common CRUD pattern: Create, Read, Update, and Delete.

The options can be provided directly to resources method. You may also want to look at using the scope, prefix which can provide similar results with less duplication by making use of blocks. The scope and prefix docs are below.

2.3 param identifier

You can change the variable identifier in the path with the param option. Example:

3.2 member and collection options

Named routes helper methods are also generated when you use the member or collection keywords with your route. Refer to the members and collections docs below for examples.

3.3 Named routes path and url helper

For each _path method there is a corresponding _url method. The _url method includes the host. Here’s a table with examples:

As / Prefix

Path Helper

Url Helper

posts

posts_path => /posts

posts_url => localhost:8888/posts

new_post

new_post_path => /posts/new

new_post_url => localhost:8888/posts/new

post

post_path(1) => /posts/1

post_url(1) => localhost:8888/posts/1

edit_post

edit_post_path(1) => /posts/1/edit

edit_post_url(1) => localhost:8888/posts/1/edit

3.4 Disable generated url helpers

You can disable the generation of the url helper with as: :disabled. Example:

get"posts",to: "posts#index",as: :disabled

You may want to do this if 2 generated url helpers happen to step on each other.

4. Singular Resource

There are sometimes resources that always look up the same id. A good example of this is a profile resource. The profile resource always looks up the currently logged-in user. We do not need to have the user id as a part of the url path. The singular resource method is useful here. Example:

This makes for nice clean URLs. For example, we can get all the comments that belong to a post with /posts/1/comments.

Here are the generated named routes helpers:

As / Prefix

Helper

posts

posts_path

new_post

new_post_path

post

post_path(post_id)

edit_post

edit_post_path(post_id)

post_comments

post_comments_path(post_id)

new_post_comment

new_post_comment_path(post_id)

post_comment

post_comment_path(post_id, id)

edit_post_comment

edit_post_comment_path(post_id, id)

Note: When resources are nested the parent path variable names all become :post_id. This is because path variable siblings must all be the same for API Gateway. More details here: API Gateway Considerations.

6. Resource Members and Collections

Within the resources block you can use the member or collection options as a shorthand to create additional resource related routes. Example: