You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
When I first embarked on creating an API for a project, I couldn’t find a ton of resources on how to test it with RSpec, so I decided to write a blog post about it. Let’s say we’re building an app that allows users to list their second bedrooms to short-term guests. We all love Airbnb :) This would be an application with many models that have complex associations, but let’s focus on what a host ca
Rails4から事実上標準になったっぽいJbuilderを使って、Grape+RailsなWebAPIのJSONフォーマットを柔軟に作ってみる。has_manyなどで深い階層のモデルを使ってAPIを作ると面倒くさいことが多いんだけど、Jbuilderならシンプルに書くことが出来る。 他のGemでActiveModel::Serializersっていうのもあったけど、こっちはモデルで出力フォーマットを定義していくタイプっぽくて、複雑なJSONフォーマットにしようとすると面倒。Viewで定義できるJbuilderの方が良さげ。ActiveModel::SerializersはモデルとAPIが1対1の時に良いのかも。 前提 Rails v4.1 grape v0.9.0 grape-jbuilder v0.2.0 Gemfile
Photo by Gonzalo Baeza | Flickr - Photo Sharing! RailsでJSONを返すAPIを作成し、また、APIのテスト方法も説明します。 JSONを返すAPIは、RailsのActiveSupportより拡張されたto_jsonメソッドとDMMが開発したjbuilderというGemを使います。 APIのテストにはおなじみのRSpec3を使います。 動作確認 Rails 4.1.7 jbuilder 2.2.6 rspec-rails 3.1.0 factory_girl 4.5.0 目次 1. 前提条件 2. APIの作成 2.1. 1つのコントローラーでHTMLやJSONを返すAPI 2.2. JSONのみを返すAPI 2.3. APIのバージョニング 3. APIのテスト 3.1. テストファイルの準備 3.2. 一覧(index)APIのテス
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く