Add RESTful routing with resources function#149
Merged
Conversation
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))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
:actionand:methodin route definitionspath-controllerto match routes by both path and HTTP methodresourcesfunction to generate 7 standard RESTful routes in a single call:only/:exceptoptions to selectively include or exclude actionsdo-get/do-postdispatchUsage
Changed files
src/controller/base-controller.lisp— Addactionslot, HTTP method-awarepath-controller,resourcesfunctionsrc/middleware/clails-middleware.lisp— Addcall-actionfunction and action dispatch logictest/controller/base-controller.lisp— Add routing and resources testsdocument/controller.md/document/controller_ja.md— Add RESTful routing documentationTest plan
resourcesgenerates 7 routes in correct order/todos/newis not matched as:idparameter:only/:exceptoptions filter actions correctly:actioncontinue to dispatch todo-getetc. (backward compatibility)