Skip to main content

32 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

APIs


Transcripts

No transcripts available. Earn a free month

Discussion


Gravatar

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!

Gravatar

Haha crap, bad edit!


Gravatar

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.

Thanks.

Gravatar

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.


Gravatar

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!


Gravatar

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...).

Gravatar

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


Gravatar

Paging using this techniques would be awesome.


Gravatar

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

Gravatar

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.


Gravatar

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


Gravatar

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.

Hugs.

Kelvin Matheus


Gravatar

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!


Gravatar
Ping. I'd like to see more AMS topics as well. 
Hopefully you're not over the topic :-D

Gravatar
On second thought, i just did some digging and it seems that AMS might be on the down turn. The repo suggests looking at https://github.com/Netflix/fast_jsonapi and http://jsonapi-rb.org/ I'm going to head over there for a spell.

Gravatar
Thank a lot for helpful tutorial Chris Oliver. I just start using MacVim couple day ago and I really excited about it. I would like to know that how do you navigate the file? something like you do at 7:20. Thank so much :D 

Login or create an account to join the conversation.