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
* rename chapter04/chapter05 from athentification to authentication
* Update fast_jsonapi to jsonapi-serializer for rails6 en
Co-authored-by: Promise Chukwuenyem <[email protected]>
Copy file name to clipboardExpand all lines: rails6/en/chapter06-improve-json.adoc
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,20 +58,20 @@ The content of the `data` key is also quite strict:
58
58
* properties of the objects must be placed in an `attributes` key
59
59
* links of the objects must be placed in a `relationships` key
60
60
61
-
In this chapter we will customize the JSON output using Netflix's gem: https://github.com/Netflix/fast_jsonapi[fast_jsonapi]. Luckily for us, they already implement all https://jsonapi.org/[JSON:API] specifications.
61
+
In this chapter we will customize the JSON output using https://github.com/jsonapi-serializer/jsonapi-serializer[jsonapi-serializer] gem (fork of Netflix's https://github.com/Netflix/fast_jsonapi[fast_jsonapi] gem) . Luckily for us, it already implements all https://jsonapi.org/[JSON:API] specifications.
62
62
63
-
So let's install the gem `fast_jsonapi`:
63
+
So let's install the gem `jsonapi-serializer`:
64
64
65
65
[source,bash]
66
66
----
67
-
$ bundle add fast_jsonapi
67
+
$ bundle add jsonapi-serializer
68
68
----
69
69
70
70
You should be ready to continue with this tutorial.
71
71
72
72
== Serialize user
73
73
74
-
FastJSON API uses *serializers*. Serializers represent Ruby classes that will be responsible to converting a model into an https://ruby-doc.org/core-2.6.3/Hash.html[`Hash`] or a JSON.
74
+
JSON:API Serializer uses *serializers*. Serializers represent Ruby classes that will be responsible to converting a model into an https://ruby-doc.org/core-2.6.3/Hash.html[`Hash`] or a JSON.
75
75
76
76
So we need to add a `user_serializer.rb` file. We can do it manually but the gem provides a command-line interface to do it:
77
77
@@ -87,7 +87,7 @@ This has created a file called `user_serializer.rb` under the `app/serializers`
87
87
.app/serializers/user_serializer.rb
88
88
----
89
89
class UserSerializer
90
-
include FastJsonapi::ObjectSerializer
90
+
include JSONAPI::Serializer
91
91
attributes :email
92
92
end
93
93
----
@@ -111,12 +111,12 @@ There you go. As you can see this is easy. Now we can use our new _serializer_ i
111
111
class Api::V1::UsersController < ApplicationController
Until now it was easy thanks to the gem https://github.com/Netflix/fast_jsonapi_jsonapi[fast_jsonapi]. In the coming chapters, we will start building the `Order` model that will involve users in the products.
983
+
Until now it was easy thanks to the gem https://github.com/jsonapi-serializer/jsonapi-serializer[jsonapi-serializer]. In the coming chapters, we will start building the `Order` model that will involve users in the products.
There is currently an implementation to do caching with the gem `fast_jsonapi` which is really easy to handle. Although in older versions of the gem, this implementation can change, it does the job.
430
+
There is currently an implementation to do caching with the gem `jsonapi-serializer` which is really easy to handle. Although in older versions of the gem, this implementation can change, it does the job.
431
431
432
432
If we request the product list, we will notice that the response time takes about 174 milliseconds using cURL:
433
433
@@ -446,7 +446,7 @@ By adding only one line to the `ProductSerializer` class, we will see a signific
0 commit comments