Skip to main content

30 JSON:API Format and Active Model Serializers

Episode 168 · January 17, 2017

Learn how to format your API easily using Active Model Serializers and the JSON:API spec



No transcripts available. Earn a free month


Raphael Ramos on

Very nice video as always, but there's an editing problem on your video. Check it between 15:00 and 17:00. You actually repeat the same thing twice, but the wordings you use is different, I guess you forgot to remove one of those when editing the video.

But anyway, great video!

Chris Oliver (159,840 XP) on

Haha crap, bad edit!

Zulhilmi Zainudin (260 XP) on

Chris, what if my current API code base doesn't really in RESTful shape? Does AMS still can help?

Example of my current routes:

1. /transaction_history.json (I don't have TransactionHistory model)
2. /buy.json (I don't have Buy model)
3. /user_status.json (mixed data between User model and several other models)

I'm not using AMS now. Still using render :json => {} approach inside my API controller.


Chris Oliver (159,840 XP) on

AMS doesn't care about your URLs, it just takes models and turns them into JSON. You can use any routes you want. Ideally for JSON:API spec, you'll want some restful routes for the objects, but it's also fine to have routes like you mentioned for ease of use. I think of routes for concepts often, it doesn't have to be specifically for a model. For example, your routes make sense because they offer up clear endpoints for different concepts for each one.

Lucas Boberg (10 XP) on

I would love it if you would do as many tutorials on api's as possible, and I would like it if you did a tutorial on the doorkeeper gem as well.

By the way great episode!

Pavel Rodionov (10 XP) on

Hi Chris. Thanks for video.
Can you tell me - why json api is better than basic json output?
Json APi has more unneeded information(big response size). It's terrible to work with Json API from JS clients, because you will need to write a normalizer for get access to data through dot(location.recordings...).

Kelvin Firmino (1,770 XP) on

This is a really interesting question. I was thing about the same thing when I saw this much of information.

Kashyap H Patel (410 XP) on

Paging using this techniques would be awesome.

Szilard Magyar (2,100 XP) on

Hey Chris! What would you recommend for pagination? Using some gems or doing it from scratch? Could you also point out some great resources on the topic? Thx

Chris Oliver (159,840 XP) on

I would recommend either will_paginate or Kaminari. Both work really well and only have minor API differences between the two. They both have over 13M downloads too, so they're similarly popular and I wouldn't really say one is better than the other. If you use something like Administrate or something that already depends upon one, then I'd say to just use that for your app as well.

I'll be making a video how to add the pages into the JSON api spec so you can see how that's done.

Tiago Santos (110 XP) on

Hey, did you ended up doing a second video with the links and pagination? :)

Kelvin Firmino (1,770 XP) on

Hey Chris. Thanks for the awesome video.

I'd like to know about your courses sooner!

Would be wonderful if you add the links information in a video as mentioned in this video.

In addition, I had asked at work why they did not use this JSON Api format and they said to me that HAL and HATEOAS are better.

Do you know which are the advantages of those three ways of JSON Format?

Thanks so much for your attention.


Kelvin Matheus

zerocool81 on

Hi Chris, have you recorded another screencast for rendering out the links for objects as JSON:API recommends? I don't seem to have much luck finding any other tutorials on the subject. You're the closest I've found... I'd really like to figure out how to do that. Thanks!

Login or create an account to join the conversation.