{"id":16754898,"url":"https://github.com/twof/vaporcrudrouter","last_synced_at":"2025-06-11T23:02:53.102Z","repository":{"id":41180408,"uuid":"150809788","full_name":"twof/VaporCRUDRouter","owner":"twof","description":"A Rails-inspired extension to Vapor's routing system","archived":false,"fork":false,"pushed_at":"2021-11-27T01:08:18.000Z","size":220,"stargazers_count":68,"open_issues_count":1,"forks_count":7,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-08T09:43:19.179Z","etag":null,"topics":["rails","routing","swift","vapor","vapor-4","vapor-swift","vapor4"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twof.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-29T01:07:55.000Z","updated_at":"2024-12-22T19:06:54.000Z","dependencies_parsed_at":"2022-08-18T23:11:30.252Z","dependency_job_id":null,"html_url":"https://github.com/twof/VaporCRUDRouter","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/twof/VaporCRUDRouter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twof%2FVaporCRUDRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twof%2FVaporCRUDRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twof%2FVaporCRUDRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twof%2FVaporCRUDRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twof","download_url":"https://codeload.github.com/twof/VaporCRUDRouter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twof%2FVaporCRUDRouter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259360728,"owners_count":22845817,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rails","routing","swift","vapor","vapor-4","vapor-swift","vapor4"],"created_at":"2024-10-13T03:06:17.868Z","updated_at":"2025-06-11T23:02:53.085Z","avatar_url":"https://github.com/twof.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CrudRouter\n\nCrudRouter is a Rails-inspired extension to Vapor's routing system that makes it as simple as possible to set up CRUD (Create, Read, Update, Delete) routes for any `Model`. CrudRouter provides an API very similar to Rails' `resources` but with a few extra features including automatic responder generation and type safety. \n\n## Installation\nWithin your Package.swift\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/twof/VaporCRUDRouter.git\", from: \"1.0.0\")\n]\n```\nand\n\n```swift\ntargets: [\n    .target(name: \"App\", dependencies: [\"CrudRouter\"]),\n]\n```\n\n## Usage\n\nWithin your router setup (`routes.swift` in the default Vapor API template)\n```swift\nrouter.crud(register: Todo.self)\n```\nThat's it!\n\nThat one line gets you the following routes.\n\n```\nGET     /todo       // returns all Todos\nGET     /todo/:id   // returns the Todo with :id\nPOST    /todo       // create new Todo with provided body\nPUT     /todo/:id   // update Todo with :id\nDELETE  /todo/:id   // delete Todo with :id\n```\n\nGenerated paths default to using lower snake case so for example, if you were to do\n\n```swift\nrouter.crud(register: SchoolTeacher.self)\n```\nyou'd get routes like\n\n```\nGET     /school_teacher\nGET     /school_teacher/:id\nPOST    /school_teacher\nPUT     /school_teacher/:id\nDELETE  /school_teacher/:id\n```\n\n#### Path Configuration\nIf you'd like to supply your own path rather than using the name of the supplied model, you can also do that\n\n```swift\nrouter.crud(\"account\", register: User.self)\n```\nresults in\n\n```\nGET     /account\nGET     /account/:id\nPOST    /account\nPUT     /account/:id\nDELETE  /account/:id\n```\n\n#### Nested Relations\nSay you had a model `User`, which was the parent of another model `Todo`. If you'd like routes to expose all `Todo`s that belong to a specific `User`, you can do something like this.\n\n```swift\nrouter.crud(register: User.self) { controller in\n    controller.crud(children: \\.todos)\n}\n```\n\nresults in\n\n```\nGET     /user\nGET     /user/:id\nPOST    /user\nPUT     /user/:id\nDELETE  /user/:id\n\nGET     /user/:id/todo      // returns all Todos belonging to the User with :id\nGET     /user/:id/todo/:id  // returns the Todo with :id belonging to the User with :id\nPOST    /user/:id/todo      // creates a new Todo belonging to the User with :id\nPUT     /user/:id/todo/:id  // updates the Todo with :id belonging to the User with :id\nDELETE  /user/:id/todo/:id  // deletes the Todo with :id belonging to the User with :id\n```\n\nwithin the supplied closure, you can also expose routes for related `Parent`s and `Sibling`s\n\n```swift\ncontroller.crud(children: \\.todos)\ncontroller.crud(parent: \\.todos)\ncontroller.crud(siblings: \\.todos)\n```\n\n#### Including or Excluding Specific Routes\nIf you'd like to register a `Model`, but you don't want every route to be available, you can specify the ones you want, or exclude the ones you don't.\n\n```swift\nrouter.crud(register: Todo.self, .except([.create, .delete])) { controller in\n    controller.crud(parent: \\.owner, .only([.read]))\n}\n```\n\nresults in\n\n```\nPUT /todo/:id\nGET /todo/:id\nGET /todo\n\nGET /todo/:id/tag/:id\n```\n\n### Future features\n- query parameter support\n- PATCH support\n- automatically expose relations (blocked by lack of Swift reflection support)\n- generate models and rest routes via console command\n- Publicable support ([potentially blocked by a compiler bug](https://forums.swift.org/t/how-to-select-different-associated-type-based-on-type-constraints/17214))\n- Fine grained per route public return models\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwof%2Fvaporcrudrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwof%2Fvaporcrudrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwof%2Fvaporcrudrouter/lists"}