active_model_serializers/ActiveModelSerializers/Jsonapi.html
2016-04-05 11:05:22 -05:00

178 lines
5.7 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Module: ActiveModelSerializers::Jsonapi
&mdash; Documentation by YARD 0.8.7.6
</title>
<link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
hasFrames = window.top.frames.main ? true : false;
relpath = '../';
framesUrl = "../frames.html#!ActiveModelSerializers/Jsonapi.html";
</script>
<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
</head>
<body>
<div id="header">
<div id="menu">
<a href="../_index.html">Index (J)</a> &raquo;
<span class='title'><span class='object_link'><a href="../ActiveModelSerializers.html" title="ActiveModelSerializers (module)">ActiveModelSerializers</a></span></span>
&raquo;
<span class="title">Jsonapi</span>
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../class_list.html">
Class List
</a>
<a class="full_list_link" id="method_list_link"
href="../method_list.html">
Method List
</a>
<a class="full_list_link" id="file_list_link"
href="../file_list.html">
File List
</a>
</div>
<div class="clear"></div>
</div>
<iframe id="search_frame"></iframe>
<div id="content"><h1>Module: ActiveModelSerializers::Jsonapi
</h1>
<dl class="box">
<dt class="r1 last">Defined in:</dt>
<dd class="r1 last">lib/active_model_serializers/register_jsonapi_renderer.rb</dd>
</dl>
<div class="clear"></div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Based on discussion in <a
href="https://github.com/rails/rails/pull/23712#issuecomment-184977238">github.com/rails/rails/pull/23712#issuecomment-184977238</a>,
the JSON API media type will have its own format/renderer.</p>
<p>&gt; We recommend the media type be registered on its own as jsonapi when a
jsonapi Renderer and deserializer (Http::Parameters::DEFAULT_PARSERS) are
added.</p>
<p>Usage:</p>
<p>ActiveSupport.on_load(:action_controller) do</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>active_model_serializers/register_jsonapi_renderer</span><span class='tstring_end'>&#39;</span></span>
</code></pre>
<p>end</p>
<p>And then in controllers, use `render jsonapi: model` rather than `render
json: model, adapter: :json_api`.</p>
<p>For example, in a controller action, we can: respond_to do |format|</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_format'>format</span><span class='period'>.</span><span class='id identifier rubyid_jsonapi'>jsonapi</span> <span class='lbrace'>{</span> <span class='id identifier rubyid_render'>render</span> <span class='label'>jsonapi:</span> <span class='id identifier rubyid_model'>model</span> <span class='rbrace'>}</span>
</code></pre>
<p>end</p>
<p>or</p>
<p>render jsonapi: model</p>
<p>No wrapper format needed as it does not apply (i.e. no `wrap_parameters
format: [jsonapi]`)</p>
</div>
</div>
<div class="tags">
</div><h2>Defined Under Namespace</h2>
<p class="children">
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Jsonapi/ControllerSupport.html" title="ActiveModelSerializers::Jsonapi::ControllerSupport (module)">ControllerSupport</a></span>
</p>
<h2>Constant Summary</h2>
<dl class="constants">
<dt id="MEDIA_TYPE-constant" class="">MEDIA_TYPE =
</dt>
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>application/vnd.api+json</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
<dt id="HEADERS-constant" class="">HEADERS =
</dt>
<dd><pre class="code"><span class='lbrace'>{</span>
<span class='label'>response:</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>CONTENT_TYPE</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span> <span class='op'>=&gt;</span> <span class='const'>MEDIA_TYPE</span> <span class='rbrace'>}</span><span class='comma'>,</span>
<span class='label'>request:</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ACCEPT</span><span class='tstring_end'>&#39;</span></span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span> <span class='op'>=&gt;</span> <span class='const'>MEDIA_TYPE</span> <span class='rbrace'>}</span>
<span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_freeze'>freeze</span></pre></dd>
</dl>
</div>
<div id="footer">
Generated on Tue Apr 5 11:04:37 2016 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.8.7.6 (ruby-2.2.2).
</div>
</body>
</html>