Skip to content

Add RESTful routing with resources function#149

Merged
tamurashingo merged 4 commits into
developfrom
feature/restful-routing
May 13, 2026
Merged

Add RESTful routing with resources function#149
tamurashingo merged 4 commits into
developfrom
feature/restful-routing

Conversation

@tamurashingo

Copy link
Copy Markdown
Owner

Summary

  • Add action-based routing that dispatches to named controller methods (index, show, new, etc.) using :action and :method in route definitions
  • Extend path-controller to match routes by both path and HTTP method
  • Add resources function to generate 7 standard RESTful routes in a single call
  • Support :only / :except options to selectively include or exclude actions
  • Maintain full backward compatibility with existing do-get / do-post dispatch
  • Update controller documentation (English and Japanese)

Usage

;; Generate all 7 standard RESTful routes
(setf clails/environment:*routing-tables*
  `(,@(resources "todos" "myapp/controllers/todo-controller:<todo-controller>")))

;; Generate only specific actions
(resources "todos" "controller" :only '(:index :show))

;; Exclude specific actions
(resources "todos" "controller" :except '(:destroy))

Changed files

  • src/controller/base-controller.lisp — Add action slot, HTTP method-aware path-controller, resources function
  • src/middleware/clails-middleware.lisp — Add call-action function and action dispatch logic
  • test/controller/base-controller.lisp — Add routing and resources tests
  • document/controller.md / document/controller_ja.md — Add RESTful routing documentation

Test plan

  • All 64 existing tests pass
  • resources generates 7 routes in correct order
  • /todos/new is not matched as :id parameter
  • :only / :except options filter actions correctly
  • Each HTTP method × path combination routes to the correct action
  • Routes without :action continue to dispatch to do-get etc. (backward compatibility)

Enable routing by action name and HTTP method, allowing a single
controller to handle multiple actions (index, show, new, etc.)
instead of requiring separate controllers per path. Routes without
:action/:method continue to use do-get/do-post dispatch for
backward compatibility.
Introduce a resources helper that generates 7 standard RESTful
routes (index, new, create, show, edit, update, destroy) from a
resource name and controller, enabling concise route definitions
like (resources "todos" "myapp/controllers/todo-controller:<todo-controller>").
Routes are ordered so /new is matched before /:id.
Allow selective route generation by specifying which actions to
include or exclude, similar to Rails' resources routing options.
Example: (resources todos controller :except '(:destroy))
@tamurashingo tamurashingo merged commit b193f3b into develop May 13, 2026
2 checks passed
@tamurashingo tamurashingo deleted the feature/restful-routing branch May 13, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant