{"id":15603719,"url":"https://github.com/vochicong/rails-json-api","last_synced_at":"2026-01-19T22:31:20.062Z","repository":{"id":39702101,"uuid":"115013168","full_name":"vochicong/rails-json-api","owner":"vochicong","description":"a working example of Rails providing camelCase JSON API service","archived":false,"fork":false,"pushed_at":"2023-03-09T05:26:24.000Z","size":89,"stargazers_count":2,"open_issues_count":7,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-06T22:30:33.391Z","etag":null,"topics":["api","camelcase","jbuilder","json","rails","snakecase"],"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/vochicong.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-21T14:15:39.000Z","updated_at":"2021-11-22T15:25:31.000Z","dependencies_parsed_at":"2024-12-20T10:28:35.173Z","dependency_job_id":"796a3c69-4763-434f-ae6f-332b2a52419f","html_url":"https://github.com/vochicong/rails-json-api","commit_stats":{"total_commits":37,"total_committers":3,"mean_commits":"12.333333333333334","dds":0.5675675675675675,"last_synced_commit":"1dfa7debfd95167c9508e1fdf058fcf935d82d30"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vochicong/rails-json-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vochicong%2Frails-json-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vochicong%2Frails-json-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vochicong%2Frails-json-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vochicong%2Frails-json-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vochicong","download_url":"https://codeload.github.com/vochicong/rails-json-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vochicong%2Frails-json-api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28587239,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T20:45:59.482Z","status":"ssl_error","status_checked_at":"2026-01-19T20:45:41.500Z","response_time":67,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","camelcase","jbuilder","json","rails","snakecase"],"created_at":"2024-10-03T03:20:43.018Z","updated_at":"2026-01-19T22:31:20.048Z","avatar_url":"https://github.com/vochicong.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maintainability](https://api.codeclimate.com/v1/badges/6bc16f3bcc5522f2b685/maintainability)](https://codeclimate.com/github/vochicong/rails-json-api/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/6bc16f3bcc5522f2b685/test_coverage)](https://codeclimate.com/github/vochicong/rails-json-api/test_coverage)\n\n# Rails API server\n\n## 作業手順\n\nRails APIアプリを新規作成\n\n    rails new rails_api --api\n\nUser を scaffold\n\n    rails generate scaffold User full_name:string email_address:string\n\nJSON API では key として camelCase (fullName や emailAddress)を使う想定。\n\n`rails c`で User のデータを追加。\n\n簡単に動いているかどうかを見る\n\n    rails s\n    open http://localhost:3000/users.json\n    open http://localhost:3000/users/1.json\n\nPost を scaffold\n\n    rails generate scaffold post post_content:text user_id:integer\n\n`rails c`で Post のデータを追加。\n\nTODO: seeds で User と Post のテストデータを作成・保存\n\n簡単に動いているかどうかを見る\n\n    rails s\n    open http://localhost:3000/posts.json\n    open http://localhost:3000/posts/1.json\n\nRSpec のインストール（初期設定）\n\n    rails generate rspec:install\n\n## API JSON format\n\nPostman で叩いてみて、現段階の request と response の key を\nsnake_case から camelCase に変えて API JSON format 仕様とする。\n\n### Create\n\n#### Request\n\nPOST /users\n```json\n{\n    \"fullName\": \"Michal Jackson\",\n    \"emailAddress\": \"michale@gmail.com\"\n}\n```\n\n#### Response\n\n```json\n{\n    \"id\": 3,\n    \"fullName\": \"Michal Jackson\",\n    \"emailAddress\": \"michale@gmail.com\",\n    \"createdAt\": \"2017-12-17T07:28:52.052Z\",\n    \"updatedAt\": \"2017-12-17T07:28:52.052Z\",\n    \"url\": \"http://localhost:3000/users/3.json\"\n}\n```\n\n### Update\n\n#### Request\n\nPATCH/PUT /users/3\n```json\n{\n    \"fullName\": \"Michale Jack\",\n    \"emailAddress\": \"jack@gmail.com\"\n}\n```\n\n#### Response\n\n```json\n{\n    \"id\": 3,\n    \"fullName\": \"Michale Jack\",\n    \"emailAddress\": \"jack@gmail.com\",\n    \"createdAt\": \"2017-12-17T07:28:52.052Z\",\n    \"updatedAt\": \"2017-12-17T07:33:53.010Z\",\n    \"url\": \"http://localhost:3000/users/3.json\"\n}\n```\n\n## API JSON testing\n\nJSON APIのRSpecでは`JSON.parse(response.body)`がよく発生するため、\n`js_response`で済むヘルパーを導入してみました。\n\n## Manual testing\n\n\nStart Rails server\n\n    bin/rails db:migrate RAILS_ENV=development\n    rails s\n\nCreate users\n\n    curl http://localhost:3000/users -X POST -H \"Content-Type: application/json\" -d '{\"fullName\": \"Michal Jackson\", \"emailAddress\": \"michale@gmail.com\"}'\n\nGet users\n\n    curl http://localhost:3000/users\n\n## 参考\n\n- [Rails Hash#deep_transform_keys](http://api.rubyonrails.org/classes/Hash.html#method-i-deep_transform_keys-21)\n- [Jbuilder](https://github.com/rails/jbuilder)\n- [Postman](https://www.getpostman.com/)\n- [DRY-ing The JSON Response](http://aalvarez.me/blog/posts/testing-a-rails-api-with-rspec.html)\n- [Rails API Testing Best Practices](http://matthewlehner.net/rails-api-testing-guidelines/)\n\n# Rails encrypted credentials\n\nRails 5.2 から `config/credentials.yml.enc` が導入され、混乱を招いている。\n`development`, `test` では環境変数を使って、`production` (または `staging`など)で\n`encrypted credentials` を使うニーズに手軽に対応するには、\n`config/environment.rb` にクラス `Env`を導入してみた。\n\n```ruby\nclass Env\n  def self.method_missing(name, *default)\n    ENV[name.to_s] ||\n      default.first ||\n      Rails.application.credentials.send(name) ||\n      super\n  end\n\n  def self.respond_to_missing?(*)\n    true\n  end\nend\n```\n\n## 使い方\n\nシステム構成情報は、環境変数または`config/credentials.yml.enc`に設定する。\n`Env.APP_CONFIG` は `APP_CONFIG` をまず\n環境変数 `ENV` から探して、未設定の場合に `encrypted credentials` から探す。\n引数にデフォルトの値が与えられたら、`encrypted credentials` からは探さない。\n\n## 例\n\n### config/credentials.yml.enc の内容確認\n\n    $ RAILS_MASTER_KEY=289e1431050b365b62bb5917acabcc53 rails credentials:show\n    secret_key_base: 2105bc31227a27f81b901582a8bb43b35bebea2b9c3572b024184a0b06dad26fc3bb312fbc5a7069783798d22f55cf4f411ae19169dd2a78026dccfbbdc889d7\n    APP_CONFIG: encryptedConfig\n\n### 環境変数が未定義の場合、デフォルト値が使われる\n\n    $ rails runner 'puts Env.APP_CONFIG(\"default\")'\n    default\n\n### 環境変数がデフォルト値よりも優先される\n\n    $ APP_CONFIG=envVar rails runner 'puts Env.APP_CONFIG(\"default\")'\n    envVar\n\n### 環境変数が、`encrypted credentials` よりも優先される\n\n    $ RAILS_MASTER_KEY=289e1431050b365b62bb5917acabcc53 APP_CONFIG=envVar rails runner 'puts Env.APP_CONFIG(\"default\")'\n    envVar\n\n### デフォルト値が `encrypted credentials` よりも優先される\n\n    $ RAILS_MASTER_KEY=289e1431050b365b62bb5917acabcc53 rails runner 'puts Env.APP_CONFIG(\"default\")'\n    default\n\n### 環境変数もデフォルト値も未定義の場合、`encrypted credentials` が使われる\n\n    $ RAILS_MASTER_KEY=289e1431050b365b62bb5917acabcc53 rails runner 'puts Env.APP_CONFIG'\n    encryptedConfig\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvochicong%2Frails-json-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvochicong%2Frails-json-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvochicong%2Frails-json-api/lists"}