{"id":14955787,"url":"https://github.com/nix41/grape-utils","last_synced_at":"2025-10-08T18:26:42.498Z","repository":{"id":218616336,"uuid":"719325248","full_name":"Nix41/grape-utils","owner":"Nix41","description":"Group of Grape templates and utils for building APIs","archived":false,"fork":false,"pushed_at":"2024-12-13T23:23:43.000Z","size":51,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-24T10:55:05.923Z","etag":null,"topics":["api","crud","grape","grape-api","ror","ruby","rubyonrails","template"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Nix41.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-15T23:37:45.000Z","updated_at":"2024-12-13T23:22:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"510b8877-e2c8-40f4-937f-5cba7ef5928c","html_url":"https://github.com/Nix41/grape-utils","commit_stats":{"total_commits":9,"total_committers":1,"mean_commits":9.0,"dds":0.0,"last_synced_commit":"fe422ae20ef75f9c50d33e60adf971a2e515df80"},"previous_names":["nix41/grape-utils"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nix41%2Fgrape-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nix41%2Fgrape-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nix41%2Fgrape-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nix41%2Fgrape-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nix41","download_url":"https://codeload.github.com/Nix41/grape-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235426486,"owners_count":18988420,"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":["api","crud","grape","grape-api","ror","ruby","rubyonrails","template"],"created_at":"2024-09-24T13:11:48.254Z","updated_at":"2025-10-05T18:30:22.259Z","avatar_url":"https://github.com/Nix41.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grape::Utils\n\nThis gem offers some templates for basic CRUD endpoints using grape, grape-entity and grape-kaminari\n\n## Installation\n\nInstall the gem and add to the application's Gemfile by executing:\n\n    $ bundle add grape-utils\n\nIf bundler is not being used to manage dependencies, install the gem by executing:\n\n    $ gem install grape-utils\n\n## Basic Usage\n\nGiven you already have a Grape API set up, and a model `Foo`, with a `Entities:Foo`, you can Use `::Grape::Utils::Templates::Crud` as follows:\n\n```ruby\nmodule AwesomeAPI\n  module Resources\n    class Foo \u003c Base\n\n      resource :foos do\n        mount ::Grape::Utils::Templates::Crud, with: {\n          # The collection that will be used for the index endpoint\n          index: Foo.all,\n          # The ActiveModel instance that will be used to create, update and find_by!\n          model: Foo,\n          # The entity that will be used as a return type\n          entity: Entities::Foo,\n          # The required params for the Create endpoint\n          required_params: [:name]\n        }\n      end\n    end\n  end\nend\n```\n\nThis will mount 5 endpoints in your API: Index, Show, Create, Update and Delete\n\nEach of this templates can also be accessed individually if needed:\n\n```ruby\nmodule AwesomeAPI\n  module Resources\n    class Foo \u003c Base\n\n      resource :foos do\n        mount Grape::Utils::Templates::Index, with: { model: Foo, scope: Foo.all, entity: Entities::Foo }\n        mount Grape::Utils::Templates::Show, with: { model: Foo, entity: Entities::Foo }\n        mount Grape::Utils::Templates::Create, with: { model: Foo, entity: Entities::Foo}\n        mount Grape::Utils::Templates::Update, with: { model: Foo.all, entity: Entities::Foo }\n        mount Grape::Utils::Templates::Delete, with: { model: Foo, entity: Entities::Foo }\n\n        route_param :id, type: Integer do\n            get 'nested_foo' do\n                #Any other relevant logic\n            end\n        end\n      end\n    end\n  end\nend\n```\n\nThis way you can customize one of the methods to fit your situation while still using the rest as standard\n\n\n## Entities and Params\n\nThe Entities Definition is used in 2 essential ways: first as a return type, and second as the param definition for the POST and PATCH endpoints\n\nFrom the Entities exposed fields, only those with a `documentation` property will be used as a param on the POST/PATCH endpoints\n\nSo given:\n```ruby\nmodule AwesomeAPI\n  module Entities\n    class Foo \u003c Grape::Entity\n      expose :id\n      expose :name, documentation: { type: String }\n      expose :configuration, documentation: { type: JSON }\n      expose :created_at\n      expose :updated_at\n    end\n  end\nend\n```\n\nOnly `name` and `configuration` will be accepted as params in POST and PATCH endpoints, with it's corresponding types\n\n### Required Params\n\nYou can define which of the documented exposed fields of the Entity are required for the creation of the resource\nby mounting `::Grape::Utils::Templates::Crud` or `::Grape::Utils::Templates::Create` with `required_params: String[]`\n\n### ID Column\n\nBy default, it is assumed that the resources will be identified by the column `id`\nThis will be used as the route parameter of the Show, Update and Delete endpoints, and by means of which, the resource will be located\nIf you want to change the name of the column to use as id, you can\nmount the relevant templates `with{... column_id: 'field_key' }`\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/Nix41/grape-utils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Nix41/grape-utils/blob/master/CODE_OF_CONDUCT.md).\n\nParticularly I am still working on getting the gem 100% covered\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Grape::Utils project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/grape-utils/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnix41%2Fgrape-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnix41%2Fgrape-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnix41%2Fgrape-utils/lists"}