{"id":13880218,"url":"https://github.com/mindreframer/api_view","last_synced_at":"2025-04-11T03:31:20.819Z","repository":{"id":22896147,"uuid":"26244562","full_name":"mindreframer/api_view","owner":"mindreframer","description":"Friggin' fast Serializer gem extracted from chetan's adjustments to json_serialization_benchmark","archived":false,"fork":false,"pushed_at":"2015-02-04T17:56:59.000Z","size":336,"stargazers_count":67,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-25T08:42:34.954Z","etag":null,"topics":[],"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/mindreframer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-05T23:25:38.000Z","updated_at":"2024-03-15T12:49:56.000Z","dependencies_parsed_at":"2022-08-21T16:10:54.826Z","dependency_job_id":null,"html_url":"https://github.com/mindreframer/api_view","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindreframer%2Fapi_view","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindreframer%2Fapi_view/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindreframer%2Fapi_view/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mindreframer%2Fapi_view/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mindreframer","download_url":"https://codeload.github.com/mindreframer/api_view/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248335434,"owners_count":21086589,"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":[],"created_at":"2024-08-06T08:02:52.491Z","updated_at":"2025-04-11T03:31:19.720Z","avatar_url":"https://github.com/mindreframer.png","language":"Ruby","readme":"# ApiView\n\n[![Build Status](https://travis-ci.org/mindreframer/api_view.svg?branch=master)](http://travis-ci.org/mindreframer/api_view)\n[![codecov.io](https://codecov.io/github/mindreframer/api_view/coverage.svg?branch=master)](https://codecov.io/github/mindreframer/api_view?branch=master)\n\nObject serializer with\n  - small codebase\n  - focus on performance\n  - benchmarks are guiding the implementation\n  - only MultiJson as sole dependency\n\n\nThe initial code was copied from `chetan` and wrapped into a gem with unit-tests and a bit more convenient API ( [original links](#original-links) )\n\n\n\n### Why should you even care? Is (... insert your favourite ruby serializer ... ) not good enough?\n\n  - you want great performance\n  - you care about object allocations (less garbage to collect for the Ruby VM)\n  - you want **blazing** fast test suite, so that you can switch globally the serialization off and test just the shape of the resulting Hash object\n    -\u003e no converting to JSON, then parsing JSON back and checking values on it, that sux!\n  - really small and clean codebase\n  - zero dependencies (NO ACTIVESUPPORT!), but you should use MultiJson + OJ for best performance.\n  - unit-tested and with 100% test coverage\n\nApiView gives you all that and stays very small doing that.\n\n## Installation\n\n    ## Add this line to your application's Gemfile:\n    gem 'api_view'\n\n\n    ## And then execute:\n    $ bundle\n\n\n## Usage\n\n  - you inherit from ApiView::Base\n  - you say, what model should be serialized by default with this serializer (optional)\n  - you specify an array of attributes, that will be copied from the object in serializer\n  - you tell how you main object is called (defaults to `object` / `obj`)\n  - you implement `instance_convert`-method for further customization of the serialization\n    -\u003e `field` - a setter method, that also accepts `via: SomeSerializerApiView`\n\n\n        class EventApiView \u003c EventSummaryApiView\n          # default serializer for BoxScore, will be picked, if none other was given\n          for_model ::Event\n\n          # the attributes to copy from the object\n          attributes :share_url, :sport_name\n\n          # the name of your main object, optional\n          main_object :event\n\n          # the method to add additional logic + fields\n          def instance_convert\n            # just a setter method with optional serializer for that sub-object\n            field :box_score, event.box_score, via: BasketballBoxScoreApiView\n          end\n        end\n\n\n\n\n        ## a more complete example\n        class Event\n          attr_accessor :game_date, :game_type, :status\n        end\n\n        class EventSerializer \u003c ::ApiView::Base\n          attributes :game_date, :game_type, :status\n          main_object :event\n          for_model ::Event\n\n          # this is your chance to do extra work\n          def instance_convert\n            field :away_team,  \"any value here\"\n          end\n        end\n\n        e = Event.new; e.game_date = Time.now; e.game_type = 'baseball'; e.status = 'won'\n        EventSerializer.render(e)\n\n        # because we configured the mapping from serializer to a Ruby class, this also works:\n        ApiView::Engine.render(e)\n\n\n\n  For more examples take a look into the `example/`-folder and run the benchmark script via `ruby example/benchmark.rb`.\n\n\n\n## Developement\n\n    # run tests\n    $ sh/test\n\n\n\n\n## Contributing\n\n1. Fork it ( https://github.com/mindframer/api_view/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n\n\n## Benchmark numbers (ApiView vs the rest of the pack)\n\n                                                  user     system      total        real       allocations      memsize\n    RABL Ultra Simple                         4.860000   0.620000   5.480000 (  5.493406)              664        25787\n    AMS Ultra Simple                          0.220000   0.000000   0.220000 (  0.220079)               26          650\n    Presenters Ultra Simple                   0.140000   0.000000   0.140000 (  0.152729)               24          650\n    ApiView Ultra Simple                      0.190000   0.000000   0.190000 (  0.193124)               12          842\n    -------------------------------------------------------------------------------------------------------------------\n    RABL Simple                              21.470000   3.330000  24.800000 ( 25.147988)             2265       114051\n    AMS Simple                                1.060000   0.000000   1.060000 (  1.066668)              105         2726\n    Presenters Simple                         0.610000   0.000000   0.610000 (  0.611980)               98         2918\n    ApiView Simple                            0.280000   0.010000   0.290000 (  0.292290)               17         2246\n    -------------------------------------------------------------------------------------------------------------------\n    RABL Complex                             43.930000   6.850000  50.780000 ( 51.574975)             4325       248000\n    AMS Complex                               2.150000   0.000000   2.150000 (  2.160445)              209         5851\n    Presenters Complex                        1.210000   0.010000   1.220000 (  1.220806)              201         7395\n    ApiView Complex                           0.270000   0.000000   0.270000 (  0.270517)               21         1504\n\n\n    Collection tests:\n\n                                                  user     system      total        real       allocations      memsize\n    RABL Ultra Simple: Collection             3.560000   0.600000   4.160000 (  4.182852)            43102      1977224\n    AMS Ultra Simple: Collection              0.120000   0.000000   0.120000 (  0.124631)             1914        47786\n    Presenters Ultra Simple: Collection       0.100000   0.010000   0.110000 (  0.109781)             3508        67594\n    ApiView Ultra Simple: Collection          0.050000   0.000000   0.050000 (  0.050875)              311        46986\n    -------------------------------------------------------------------------------------------------------------------\n    RABL Simple: Collection                  18.720000   3.150000  21.870000 ( 21.924020)           202905     11255130\n    AMS Simple: Collection                    0.870000   0.010000   0.880000 (  0.890479)             9714       236186\n    Presenters Simple: Collection             0.540000   0.000000   0.540000 (  0.542100)            16108       380794\n    ApiView Simple: Collection                0.160000   0.000000   0.160000 (  0.166484)              812       187386\n    -------------------------------------------------------------------------------------------------------------------\n    RABL Complex: Collection                 41.190000   6.680000  47.870000 ( 48.438854)           408015     25251570\n    AMS Complex: Collection                   2.170000   0.030000   2.200000 (  2.211721)            20114       548686\n    Presenters Complex: Collection            1.380000   0.010000   1.390000 (  1.389608)            34408       960494\n    ApiView Complex: Collection               0.150000   0.000000   0.150000 (  0.145595)             1212       113186\n\n\n## Original links:\n  - http://techblog.thescore.com/benchmarking-json-generation-in-ruby/#comment-1678429451\n  - https://github.com/chetan/json_serialization_benchmark/tree/api_view\n  - https://gist.github.com/chetan/d613e8f7d45600e1ca34\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindreframer%2Fapi_view","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmindreframer%2Fapi_view","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmindreframer%2Fapi_view/lists"}