We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

AMS, API, Rails and a developer, a Love Story

00:00

Formal Metadata

Title
AMS, API, Rails and a developer, a Love Story
Title of Series
Part Number
52
Number of Parts
94
Author
License
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
A lot of people have being using Rails to develop both their internal or external API, but building a high quality API can be hard, and performance is a key point to achieve it. I'll share my stories with APIs, and tell you how Active Model Serializer, component of Rails-API, helped me. AMS have being used across thousands of applications bringing convention over configuration to JSON generation. This talk will give you a sneak peek of a new version of AMS that we have being working on, it's new cache conventions, and how it's being considered to be shipped by default in new Rails 5.
Multiplication signSphereProcess (computing)Software as a serviceSelf-organizationInternetworkingMereologySoftware developerInterface (computing)Cartesian coordinate systemINTEGRALComputer programmingElectric generatorUser interfaceWordModel theoryBitOpen setSerial portVirtual machineTournament (medieval)Subject indexingPower (physics)Right angleOrder (biology)Data managementUniverse (mathematics)GodTheoryStudent's t-testState diagramQuicksortTable (information)Web 2.0Line (geometry)Electronic data interchangeStandard deviationVideo gameOntology1 (number)
Right angleMultiplication signReading (process)AreaMoment (mathematics)Query languageTheoryView (database)Universe (mathematics)Field (computer science)Rule of inferenceSoftware bugOrder (biology)ResultantScaling (geometry)HypermediaMereologyPoint (geometry)NP-hardStrategy gameUsabilityTrailType theoryQuicksortBitSerial portFunction (mathematics)User interfaceBootingLoginAttribute grammarEndliche ModelltheorieProcess (computing)Revision controlGoodness of fitCartesian coordinate systemFacebookLine (geometry)CodeData conversionSoftware developerObject (grammar)Stability theoryFunctional (mathematics)Projective planeConfiguration spaceXML
Arithmetic meanMereologyMultiplication signMedical imagingLink (knot theory)Moment (mathematics)ResultantLine (geometry)WordView (database)Green's functionRevision controlForm (programming)BuildingSoftware developerCubeMathematicsBitStandard deviationClient (computing)Projective planeAdaptive behaviorSerial portAttribute grammarFile formatModel theoryPointer (computer programming)INTEGRALComputer animation
Right angleNumberWordBuildingModel theoryRevision control
Software developerFunctional (mathematics)Model theoryStapeldateiCache (computing)Software testingMultiplication signImplementationExecution unitWordGroup actionComputer animation
View (database)Moment (mathematics)WordComputer virusMultiplication signSerial portGame controllerSubject indexingKey (cryptography)Cache (computing)Mathematical optimizationDifferent (Kate Ryan album)Cartesian coordinate systemAttribute grammarMereologyGroup actionComputer animation
MereologyMetreCache (computing)Multiplication signTheory of relativityExecution unitAttribute grammarSerial portComputer animationLecture/Conference
Serial portAttribute grammarMathematicsMultiplication signDiscounts and allowancesCache (computing)MereologyBitRight angleSpiralSocial classSign (mathematics)1 (number)
ImplementationTrailAmerican Mathematical SocietyDrop (liquid)Multiplication sign2 (number)Dependent and independent variablesTouch typingDampingCore dumpRevision controlBenchmarkCartesian coordinate systemSoftware developerOpen setModel theoryCache (computing)Level (video gaming)Rule of inferenceInsertion lossWordSystem callComputer configurationPower (physics)AreaMoment (mathematics)1 (number)Mathematical optimizationTheorySemiconductor memoryReal numberBit rateUniverse (mathematics)MereologyRight angleGodComputer animation
Computer animation
Transcript: English(auto-generated)
We all have been using it, and it's really special for the internet to use it as a mobile.
APIs is not a new technology, it has been used way before the internet comes. And the internet has switched it even further by increasing the power of how machines can communicate with other machines.
How this mobile and wearable liners are coming out, and how this movement that is going on right now is pushing even further. We as developers have been using APIs, we have been using radios, and a lot of other tools and other liners to help us to do great APIs and integrate APIs in a lot of times.
My name is Tom Mora, I'm co-founder of Jifco, we are a SaaS organization. This is how you can find your mirror and internet in general. And today we are going to talk about AMS, API, Rails, and an adapter.
And everything will be titled by a blockbuster. So yeah, I'll try to make the blockbuster the short part. I probably should get started with it. So for those that don't know, I'm from Brazil. And Brazil is awesome.
Actually, this is how far I am from home right now, just to talk to you. It's like a 10 hour flight. And what is funny is that every time, every time that I go to every conference in the world and I tell them that I'm from Brazil, everybody asks me about the streets, the lakes, and all this stuff.
Everybody asks me about the trees, the lakes, and it's really fun. But actually, the thing that I came from is something like this. There are no trees, no lakes, no animals at all, and actually the largest city of the whole Americas. And also the largest city of the whole southern hemisphere.
Yeah, it's pretty big. We have a lot of traffic, a lot of gems. So this is a picture of my usual Friday night. You can easily be caught on one of those. What is fun about this picture is that if you take a look at this laptop, even the motorcycles are having this job.
So yeah, it's pretty tough to have fun. Yeah, we proceeded a lot to have fun and a lot to hang out. And one of the major tournaments that we had in our country is soccer. Soccer is huge in Brazil.
Every time I asked our CTO, it was called All Potatoes, and it was a lot of fun. I talked a little bit about it on LumiConf. If you want to know more about it, you can watch the conference now.
We are a couple weeks away from the World Cup, and we are enough users. We are about to get in that location. You can imagine, we have a relationship, we have indexes that were missing, and we also had no cash at all.
So our APIs were really, really serious about it.
Like, we are really going down for the World Cup, and I didn't know what I should do. So that was when I followed up. EMS. EMS, how many of you have used an active model serializer?
Alright, so you've heard a lot of these thoughts. But first, let's take it easy. This is when I found out I always loved Opens First, and I was about to contribute with people into building new things. But at that time, I really found love with an active model serializer and Rails API. For those that don't know, I'm one of the contributors for Rails API and an active model serializer.
We are doing an amazing job, I talked a little bit about it from the end of the talk. But first, to get us started, let's talk a little bit about API. API stands for Application Programming Interface. And I would like to dive into a word of the definition, that it's interface.
Like, we are so worried nowadays about interface generation. Everybody knows how much user experience is important to an application. Everybody knows how much a user interface is important, and how much it can really take you apart from a bunch of other applications.
But what we usually forget is that APIs are also a kind of interface. Because your users are going to use it, or your customers, or your developers, or your team, or other developers are going to integrate with it.
So yeah, we should be putting the same fork and the same amount of technology and the fork in developing APIs as we do with the usual user interface and user experience. Because APIs can really be one of the great assets of a company.
If we take a look at Facebook, for example, Facebook is the major and the biggest ever made social network in the history of humanity. And I don't know if you realize how much the API, or their API, helped them to achieve it. Like, nowadays we are using Japan, signing in with Facebook movements all across the web.
Like, we assume every time that we build a new application that we are going to integrate with Facebook. So yeah, their API has been like a major tool in their expanding process.
But it also can be one of the greatest liabilities of a company. Because if you don't write a good API, it will definitely come back to haunt you. You are going to have to invest money to fix it, you are going to have to invest time and people to fix it, and you will probably give a bad experience for everyone that is going to degrade you.
So the question here is, how do we build a good API? What is the definition of a good API? Well, in order to define a good API, there are 8 concepts that we have to use. Those 8 concepts is what define if you have a good API or a bad API. These concepts are performance, scalability, reusability, evocability, documentation.
It must be easy to learn, it must be easy to use, and mostly it must be hard to read huge. These 8 concepts are what define if an API is a good API or if it is a bad API.
So we have to start to worry about this. Well, there is a great talk about Joshua Blanch, he used to google this talk on 2018. And he made this code that is really precise and really will help you to achieve a good API.
An API should do one thing and do it well. So this is where we are going to start about thinking APIs for now on. An API should do one thing and do it well. But if we take a look at the technical side of it, we have a lot of tools to build APIs.
We have a lot of tools that might help us to build APIs. And I would like to talk a little bit about why Redios is the best tool to build APIs. The thing is, I would like to talk about it, but it's not. Yeah, but it's a great one. We know that there is no superability, there is a lot of null types, but Redios is a great tool.
And I will show you how we can use Redios in the development of an API. So the things about why Redios is a great tool is because if we take a look at that 8 points that I pointed out for you. That performance, scalability, hard to use, hard to misuse, all are deeply related with conventions.
If you follow conventions, you probably have a performance. It's probably easy to document. It's probably easy to use, hard to misuse, and easy to scale. So they are all deeply connected with conventions. And conventions by itself is deeply connected to Redios.
Redios is all about conventions. So yeah, this is why Redios makes Redios a great tool in development of APIs. But I have to argue something, that Redios is indeed reduced. So yeah, Redios has a lot of parts that you might not want to use, and a lot of parts that you might not want to use when developing an API.
So this is why Redios API exists. How many of you have already used Redios API? Two. What Redios API does is it removes the parts of the Redios that you don't really need and don't really want when developing an API.
And it brings new functionality that you might use and might want when using APIs. It's pretty much simple. And one of these technologies, one of these projects that Redios API has beauty in is Active Model Realizer, also known as AMX.
The easiest way to define Active Model Realizer is that it brings conventions over configurations to your data. So it follows the Redios concept, it follows the Redios logic, and it also is based on conventions. But it adds a layer in your Redios application that will handle the conversion of an object that you have into a JSON output.
So I'll show you an example of what is a serializer on a Redios application. This is what a serializer looks like in a Redios application. I'm going to go through it. So first things first, you have the definition of a serializer. No worries.
We have a line that defines the attribute boot that we want to return as JSON. In this case, title, body, and comments count. But the thing is, comments count isn't an attribute of post. So it's a virtual attribute that you create on the serializer.
So this is the method that counts the comments of a post and gives it back as a JSON. So once you have the serializer in your Redios application, this is the output that you're going to have. So you're going to have a JSON output, and every time that a post is returned to your client,
and you have an ID, title, body, and comments count. Pretty much easy, right? Alright, so we have been using AOS, I think, some years from now. The first question that was kind of stable was the O8 version. How many of you use the O8 version?
We have the O9 version. How many of you use it? And we also have been working on the O10 version. How many heard about it? So yeah, we are working really hard for several months in the O10 version.
And I would like to give you a sneak peek of it and the great features it has and it will have. And you're going to love it. I'm sure about it. So the first feature is we implemented an adapter pointer. So what it means, right now, a doctor's partner is a part of a activity model serializer
that describes how the attributes will be serialized. It means that if you would like to use an activity model serializer to return XMLs, for example, you could be an adapter by yourself and be created with an activity model serializer. So it makes it easy for people that want to use other formats other than JSON
to use an activity model serializer. And if they want to contribute beauty and contribute to the project itself by doing new adapters that don't work only with JSON. So yeah, it was a great change and a small one. So yeah, a quick win for us. So the second feature that I would like to talk about, and this one is really cool
and I really would like to focus a little bit about it because I don't know how many of you have heard about it. It's JSON API. How many of you have heard about JSON API? Alright, JSON API, the standard for building APIs in JSON.
So it started back some months ago. Some of the brilliant and greatest clients and friends that I have that I know have been working on that. So you might know Stevie Klepnick and Guido that have given another talk, another conference, another room. So they start building it and there's a lot of other brilliant people that are working on it right now.
The concept is that they want to define a standard form to build APIs and JSON APIs. And it brings all the good things that conventions always bring. So you don't have to worry about negotiating it with your other employees and your other developers.
You don't have to worry about how to integrate it or which cubes will be returned for the API. So yeah, it's really cool. It really makes it a lot easier to integrate APIs and build APIs and make it a lot faster.
We're really believing that. And we are kind of glad to announce that we already implemented the JSON API release candidate 3 in this new version. And the 1.0 version is supposed to be released on May 21. And we are already working on that. So after that release, we're probably going to also merge it with Actigo models in Realizr.
And it's really cool because if you choose to use JSON API, you could build APIs way faster, follow a comment that anyone in the world would know what it's about. Yeah, it's really cool and we're really proud of it. The next two features that I'm going to talk about are some features that I'm pretty proud of
because I'm the one that made it and I really think that it can really help a lot of developers out there because it helped me on increasing and improving my APIs back then in the world. So the first one is cache.
We have implemented a beauty in cache functionality inside of Actigo models in Realizr. So it's a totally new implementation, right, the first batch. It's optimized and it follows the Rails combination. I will show you a sneak peek of how it works. So this is a user serializer, a post serializer with a title and body attributes.
Let's say that you would like to cache it. All you have to do is add a cache method. And it's done. All you have to do is add a cache method to the serializer, any part of it, and it will be cached and it will reuse it. But you can go further than that. You can even specify a key for your cache.
Or even further than that, you can use all the Rails conventions. So you can find expirals in three hours and this caching method will expire at an average three hours. And it's really cool. So let's imagine that this serializer has a post controller. So this is a post controller with an index definition, user stuff.
So every time that a user goes to the index method, it will generate the cache. As we saw in the post serializer. The cool part is when the user goes to the show method, the same cache will be reused across every action that uses the post serializer.
So yeah, it's a really great optimization and might make a lot of difference on your application's API. The next feature that I would like to talk about, and it's another really cool feature, is fragment cache. Fragment cache can really save you a lot of time.
What it does is it always follows the Rails conventions. It also follows the Rails conventions and it's built to cache specific attributes on a serializer. I'm going to show you this thing pick up in two.
So take a look at this post serializer. It's a little bit more complex. So we still have a title, a body, and a common discount attribute. But this time we are overriding the title attribute and we are overriding the common discount attribute and generating that inside the serializer. So if you take a look at those two methods by themselves,
you're going to see that the title, despite of the modification of the usual title of the post, it definitely is cacheable. But the second attribute that calls how many comments it has, it's non-cacheable because it can change pretty quickly.
So how can we cache one part of this serializer and get the other outside and still have the improvement of the cache implementation? So right now all you have to do is add cache own title, also using the Rails conventions. You can always use the other writes,
so accept comments common, and it's okay. So this is what you can do when you put everything together. So you can define cache, you can use a key, you can use all the Rails methods like this, and you can also use it to make a fragment cache. So yeah, it's really cool, and it's a really cool two features that tie together really well.
There is this famous phrase that we got between us and all the others bring data. What about how it can be problematic? How is it concerned with the old version of active model serializer? Because this version was totally hidden.
It was written from scratch. So I made some benchmark. So if we take a look at the left version, the online version, this is what we look at like a benchmark that I made with 10,000 times loading and JSON serializer. But if we take a look at the new version, we have a drop of significantly drop of 10 seconds, obviously.
And if we use cache, we're going to see almost 15 seconds drop. So yeah, it's a really great increase of performance, and it might really help our APIs. So there's a lot of work in progress, too. We still have a lot of things to do.
We are really working hard to implement fatroach so we can push forward to have even faster response when loading a lot of cache together. We are still working on a benchmark implementation that will help us to also keep track of the performance issues
whenever we need it. And there's one more thing I'd like to talk about that is really cool, and I'm not sure if even I believe it. It's that we have just released an AMS open like today, early this morning,
just because of RailsConf. So you are always able to use this as you would. So you are always able to update your JAMs, you're able to update your applications, and to use as you go on this realizer. I'd like to try something new here.
So if you'd like to compete about it, you can use the hashtag AMS-TAM. Yeah, it will be fun, like, whoa, what is AMS-TAM? Let's check it out. So yeah, use the hashtag AMS-TAM alongside the RailsConf and the people will be concerned about what it is, and you should check this out.
So we have released it this morning. You're already able to update it. We still have a lot of work to do, but yeah, it's really great. And actually, I have another thing to talk about that's really cool. I'm not sure yet, but I think that I should share it with you because I'm a little excited about it. We have been in touch with a Rails core team for some weeks from now,
and we're really excited about the possibility of AMS joining the Rails as the full. So you would be able to use it in any Rails application. It's not for sure yet, but we have been going through it, and it seems like it's going to happen, and I'm really glad to share it with you
so we can push forward and make it happen. I'd also like to use special things for the whole AMS Rails API team. They are amazing, specifically those four amazing guys that I have been closely working with for the last months.
There's a lot of other contributors, a lot of amazing developers and amazing people that have helped us out, but those four people who are really amazing, they really have been helping me during this. Actually, I have been learning for them a lot, and I think that I ended up going too fast. I was going to take another 15 minutes,
but I think it's great because we have some time for questions. I would like to thank you all for being here and letting me know that it was amazing to talk with you guys. Thank you.