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
せっかくなのでデフォルト(YAML)、Oj(json)、MessagePackでベンチマークも取ってみました。 保存するデータは http://json-generator.appspot.com/ ここで適当に作ったものをロードして突っ込んでます。 DBに保存していたりしますが、単純にそれぞれのdumpとloadの差です。 create_table :articles, force: true do |t| t.column :body, "MEDIUMTEXT", null: false t.timestamps null: false end create_table :oj_articles, force: true do |t| t.column :body, "MEDIUMTEXT", null: false t.timestamps null: false end creat
Rails での JSON API 実装まとめ 前後リンク RESTful API のおさらい Rails での JSON API 実装まとめ スキーマファースト開発 The NEXT of REST Ruby on JSON の図のような流れになるんですが、それぞれ見ていきます。 to_json (2011-2013 頃) 2011-2013 年頃、僕らは render :json を使っていました。 render json: @user render json: @user.to_json として User#as_json や User#to_json を利用します。 この頃はまだ SPA という言葉もなく、ネイティブアプリもそこまで流行っていなかったので これで十分だったのですが、どんどん API に世の中が寄っていき、限界を迎えます。 この頃のツラみ JSON を組み立てるのが大変
Google グループでは、オンライン フォーラムやメール ベースのグループを作成したり、こうしたフォーラムやグループに参加したりすることで、大勢のユーザーと情報の共有やディスカッションを行うことができます。
There are several articles/discussions on parallels of PUT vs PATCH and when to use one before other. Also the main struggle recent years seems to be how to translate the RFC proposal for PATCH JSON format. I’ve decided to spam the internet with one more opinionated article on this topic trying to explain everything one more time. First of all I’m a Ruby on Rails developer so I will reference some
One of the major requirements for any online business is to have a backend that either provides or can be extended to provide an API response. Building websites with static HTML and simple jquery ajax is coming to an end. In this era, Javascript frameworks rules the market. Hence, it is a good decision for the database to support JSON, as JSON is becoming the glue that connects the frontend and b
There is a world where developers need never worry about poorly formatted JSON. This is not that world. If a client submits invalid / poorly formatted JSON to a Rails 3.2 or 4 app, a cryptic and unhelpful error is thrown and they’re left wondering why the request tanked. Example errors The error thrown by the parameter parsing middleware behaves differently depending on your version of Rails: 3.2
TL;DR JSON Schemaを使ってこういうことが実現可能になった。 ダミーAPIサーバの提供 ドキュメントの自動生成 APIクライアントの動的定義 APIサーバのバリデータの動的定義 APIサーバのレスポンスの自動テスト JSON Schemaとは JSON SchemaというのはあるJSONのデータ構造を記述するための方法および書式の仕様で、 JSON SchemaもJSONで記述される。 これを利用すれば、リソースベースの(=RESTfulライクな)APIの仕様が簡便に記述できる。 例えば、我々のAPIはレシピとユーザというリソースを扱っていて、 それぞれCRUDのAPIを備えており、レシピはidとtitleとdescriptionという属性を持つ、 という旨をJSON Schemaで表現できる。 なんで最近ちょっと流行ってんの Mobile First、 Service Or
Ruby, Rails, Javascript | 02:04 | RubyからデータをJSON形式の文字列に変換する方法はいくつかありますが、Railsでアプリケーションを構築しているのであれば、ActiveSupport::JSONを利用するのが簡単だと思います。ActiveSupport::JSON.encodeメソッドを利用することによって、データをJSON形式の文字列に変換することができます。逆にJSON形式の文字列をデータに変換するにはdecodeメソッドを使います。 require 'rubygems' require 'active_support' data = {"id" => 3, "name" => "タマ"} json = ActiveSupport::JSON.encode(data) print json #=> {"name":"\u30bf\u30de",
yajl(Yet Another JSON Library)っていう高速なJSONライブラリがあって、 yajl こいつをrubyから使えるようにするyajl-rubyってgemがあって、これをMultiJsonのBackendに変更することで、RailsにおけるJSON処理の高速化が期待できるデス。 brianmario/yajl-ruby · GitHub 素のjson.gemと、yajl-rubyとで適当なActiveRecordオブジェクトからJSONへのエンコードと、その逆のデコードで簡単にベンチってみると、約2倍の差があることが分かる。 -------------------------------------------------------------------------------- Benchmark of json encoding/decoding json_
ActiveModel::Serializersとは Railsなどで簡単で素早くjsonを作れるgemです。 ActiveModel::Serializersより、 ActiveModel::Serializers brings convention over configuration to your JSON generation. 実際に試してはないですが、ActiveModelに依存しているだけなのでSinatraなどでも使えるはずです。 なぜActiveModel::Serializersを使うのか 簡単で速いので使ってます。 簡単 Railsではjbuilderを使うことが多いですが、記法が直感的じゃなくて多少憶えにくいかな思ってます。 json.(@message, :content, :author) => {content: 'hello', author: 'kakk
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
samuelrodgers752 | Flickr - Photo Sharing! RoarはRepresenterを使ってRESTなAPIをパース、レンダーすることができるgemです。 つまり、Roarを使うことで、RailsでJSONを返すAPIサーバーを作成したり、逆に、APIサーバーにアクセスするAPIクライアントをRubyで作れます。 下記に記載しましたが、有名なgemに比べて、メリットとしては、Rubyでサーバーとクライアントを作る場合、同じような箇所を幾分か共有できる点です。 デメリットとしては、個人的にパースやレンダー時にエラーが発生してもデバッグしづらく対処しづらいことです。 サーバー側でAPIを作る場合、「Ruby Toolbox - API Builders」によると、jbuilderやGrape、Rablなどが人気のようです。 APIにアクセスするクライアントを作
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く