{"id":15725261,"url":"https://github.com/polakowski/resourcey","last_synced_at":"2025-05-07T08:23:13.500Z","repository":{"id":56891914,"uuid":"121740816","full_name":"polakowski/resourcey","owner":"polakowski","description":"Lightweight utility for building simple resource-based JSON Apis","archived":false,"fork":false,"pushed_at":"2018-09-04T14:32:57.000Z","size":75,"stargazers_count":20,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-16T13:15:03.568Z","etag":null,"topics":["json-api","rails","ruby","ruby-gem","ruby-on-rails"],"latest_commit_sha":null,"homepage":"","language":"Ruby","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/polakowski.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-02-16T10:54:13.000Z","updated_at":"2019-09-04T15:41:49.000Z","dependencies_parsed_at":"2022-08-20T16:50:06.539Z","dependency_job_id":null,"html_url":"https://github.com/polakowski/resourcey","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polakowski%2Fresourcey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polakowski%2Fresourcey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polakowski%2Fresourcey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polakowski%2Fresourcey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polakowski","download_url":"https://codeload.github.com/polakowski/resourcey/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252840033,"owners_count":21812226,"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":["json-api","rails","ruby","ruby-gem","ruby-on-rails"],"created_at":"2024-10-03T22:20:14.517Z","updated_at":"2025-05-07T08:23:13.478Z","avatar_url":"https://github.com/polakowski.png","language":"Ruby","readme":"# Resourcey\n![Gem Version](https://img.shields.io/gem/v/resourcey.svg?label=version\u0026colorB=43bd15) ![Master build status](https://api.travis-ci.org/polakowski/resourcey.svg?branch=master) ![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)\n\nA lightweight rails gem for building resource-based APIs. It gives you some conventions and convenient solutions for rendering resources in JSON format.\n\n### Table of contents\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Controller](#controller)\n  - [Serialization](#serialization)\n  - [How to fetch](#fetch-the-data)\n  - [Pagination](#pagination)\n  - [Filtering](#filtering)\n- [Configuration](#configuration)\n- [Contributing](#contributing)\n\n## Requirements\nResourcey requires ruby 2.2.2 or higher.\n\n## Installation\nAdd Resourcey to your `Gemfile`:\n```ruby\ngem 'resourcey'\n```\n\nAnd then:\n```\nbundle\n```\n\nOr install it manually:\n```\ngem install resourcey\n```\n\n## Usage\n\n### Controller\nFor a resource called `user`, just create `UsersController`:\n```ruby\nclass Api::V1::UsersController \u003c Resourcey::Controller\nend\n```\n\nFor further reading, [click here](/docs/CONTROLLER.md).\n\n### Serialization\nNow you need a serializer, let's assume that `User` has an email and an ID, go with this:\n```ruby\nclass UserSerializer \u003c Resourcey::Serializer\n  attributes :id, :email\nend\n```\n\nFor further reading, [click here](/docs/SERIALIZER.md).\n\n### Fetch the data\n\nDon't forget to create a correct route in your `routes.rb` file, and you're good to go!\nNow just visit `/api/v1/users`, and see how your resources are rendered.\n\n```json\n/* example response */\n\n[\n  { \"id\": 1, \"email\": \"john.doe@example.com\" },\n  { \"id\": 2, \"email\": \"george.doe@example.com\" }\n]\n```\n\n### Pagination\nTo paginate resources, simply invoke `paginate` method in controller, like this:\n```ruby\nclass ResourcesController \u003c Resourcey::Controller\n  paginate\nend\n```\n\nThis will use default `:paged` paginator. Now you need to pass `page` and `per_page` parameters in `pagination` parameter value, like this:\n\n```\nhttp://api.example.com/resources?page=3\u0026per_page=10\n```\n\nThis will fetch page 3, with 10 resources per single page. That's all! Pagination can be configured globally (see \"Configuration\" below). Also you can configure every controller's pagination.\n\nFor further reading, [click here](/docs/PAGINATION.md).\n\n### Filtering\nYou can filter your resources using filter objects defined per single resource model. See below for an example:\n\n```ruby\nclass UserFilter \u003c Resourcey::Filter\n  filter :older_than do |value, scope|\n    scope.where('users.age \u003e ?', value)\n  end\nend\n```\n\nFor further reading, [click here](/docs/FILTERING.md).\n\n## Configuration\nCreate configuration file in your `config/initializers` folder, and configure as usual:\n```ruby\nResourcey.configure do |config|\n  config.some_config_variable = :some_value\nend\n```\n\n#### Available config variables\n| **config var** | **description**| **default** |\n| --- | --- | --- |\n| `default_paginator` | Name of paginator that will be used in every controller, if not configured on controller-level. Click [here](/docs/PAGINATION.md) for details. | `:paged`\n| `controller_parent` | Class or class name of controller, that `Resourcey::Controller` will inherit from. | `ActionController::Base` |\n\n## Contributing\nIf you want to take part in developing resourcey, fork this repository, commit your code, and create pull request.\n\n### Requirements\n- ruby 2.2.2 or higher\n- bundler gem\n\n### Running local tests\n- rspec\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolakowski%2Fresourcey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolakowski%2Fresourcey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolakowski%2Fresourcey/lists"}