In Relentless Pursuit of REST

Video in TIB AV-Portal: In Relentless Pursuit of REST

Formal Metadata

In Relentless Pursuit of REST
Title of Series
Part Number
Number of Parts
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 license.
Release Date

Content Metadata

Subject Area
"That's not very RESTful." As a Rails developer you've probably heard or even spoken that proclamation before, but what does it really mean? What's so great about being RESTful anyway? RESTful architecture can narrow the responsibilities of your Rails controllers and make follow-on refactorings more natural. In this talk, you'll learn to refactor code to follow RESTful principles and to identify the positive impact those changes have throughout your application stack.
Laptop Data mining Presentation of a group Arithmetic mean Computer animation Data recovery Feedback Screensaver Representational state transfer Office suite Rule of inference
Programmer (hardware) Presentation of a group Computer animation Different (Kate Ryan album) Blog Content (media) Representational state transfer Open set Parameter (computer programming) Semantics (computer science) Numerical analysis Power (physics)
Addition Email Patch (Unix) Multiplication sign Content (media) Representational state transfer Parameter (computer programming) Client (computing) Subset Uniform resource locator Computer animation Hypermedia Password Energy level Extension (kinesiology)
Mobile app Code Decision theory Patch (Unix) Consistency Maxima and minima Representational state transfer Client (computing) Cartesian coordinate system Numerical analysis Usability Process (computing) Computer animation Personal digital assistant
Business object Group action Focus (optics) Game controller Hypermedia View (database) Data storage device Pattern language Representational state transfer Object (grammar) Endliche Modelltheorie Cartesian coordinate system
Default (computer science) Group action Game controller Divisor Basis <Mathematik> Online help Mereology Event horizon Computer animation Personal digital assistant Configuration space Pattern language Set theory
Axiom of choice Point (geometry) Game controller Group action Computer file Proper map Formal language Goodness of fit User profile Array data structure Program slicing Endliche Modelltheorie Mapping Line (geometry) Cartesian coordinate system Word Message passing Password Mathematical singularity Right angle Pattern language Quicksort Table (information) Routing Row (database)
Injektivität Game controller Functional (mathematics) Dependent and independent variables Real number Software developer View (database) Mathematics Computer animation Right angle Code refactoring Object (grammar) Endliche Modelltheorie Row (database)
Game controller Implementation Group action Mapping Software developer Moment (mathematics) Mereology Flow separation Latent heat Computer animation Single-precision floating-point format Energy level Text editor Software testing Object (grammar) Endliche Modelltheorie Row (database)
Complex (psychology) Slide rule Game controller Group action Code Multiplication sign Shape (magazine) Mereology Perspective (visual) Attribute grammar Mathematics Profil (magazine) Software testing Endliche Modelltheorie Condition number Pairwise comparison Inheritance (object-oriented programming) Database transaction Line (geometry) Representational state transfer System call Digital photography Process (computing) Personal digital assistant Logic Right angle Writing Resultant
Complex (psychology) Game controller Group action Service (economics) Divisor Code Decision theory Connectivity (graph theory) Shape (magazine) Parameter (computer programming) Computer font Mathematics Meeting/Interview Different (Kate Ryan album) Natural number Flag Software testing Endliche Modelltheorie Task (computing) Database Cartesian coordinate system System call Digital photography Right angle Object (grammar) Resultant
Game controller Group action Arithmetic mean Process (computing) Order (biology) Similarity (geometry) Pattern language Right angle Formal language
Mathematics Process (computing) Code Term (mathematics) Software developer Projective plane Right angle Resultant Formal language Physical system Product (business)
Point (geometry) Slide rule Game controller Group action Implementation State of matter Multiplication sign Source code Database Bit Instance (computer science) Cartesian coordinate system Formal language Quantum entanglement Word Process (computing) Order (biology) Quicksort Object (grammar) Best, worst and average case Condition number
Pairwise comparison Game controller Code Multiplication sign Software developer Bit Formal language Mathematics Arithmetic mean Process (computing) Computer animation Blog Right angle Object (grammar) Abstraction
Code State of matter String (computer science) Single-precision floating-point format Right angle Representational state transfer Cartesian coordinate system Flow separation
Group action Validity (statistics) State of matter Cellular automaton Data storage device Line (geometry) Instance (computer science) Cartesian coordinate system Event horizon Computer animation Meeting/Interview Order (biology) Pattern language Right angle Finite-state machine Endliche Modelltheorie Logic gate
Group action Game controller Code State of matter Multiplication sign Virtual machine Water vapor Event horizon Bit rate Endliche Modelltheorie Social class Validity (statistics) Projective plane Line (geometry) Price index Representational state transfer Word Computer animation Logic Order (biology) Speech synthesis Right angle Finite-state machine Figurate number Arithmetic progression
Group action Game controller State of matter Moment (mathematics) Motion capture Interactive television Computer animation Order (biology) Authorization Pattern language Object (grammar) Endliche Modelltheorie Row (database)
Context awareness Group action Service (economics) Computer file Code Software developer Multiplication sign Data storage device Interactive television Water vapor Cartesian coordinate system Event horizon Formal language Business object Type theory Process (computing) Computer animation Order (biology) Authorization Energy level Pattern language Object (grammar) Quicksort Social class
Mobile app Dependent and independent variables Code Real number Projective plane Representational state transfer Cartesian coordinate system Perspective (visual) Product (business) Computer animation Personal digital assistant Right angle Physical system
Complex (psychology) Group action Greatest element Code State of matter Multiplication sign Image registration Coma Berenices Disk read-and-write head Perspective (visual) Coefficient of determination Computer configuration Videoconferencing Cuboid Endliche Modelltheorie Position operator Electric generator Optimization problem Shared memory Instance (computer science) Degree (graph theory) Type theory Digital photography Arithmetic mean Process (computing) Exterior algebra Order (biology) Right angle Pattern language Reading (process) Row (database) Point (geometry) Mobile app Game controller Service (economics) Computer file Connectivity (graph theory) Frequency Latent heat Gastropod shell Software testing Address space Default (computer science) Information Validity (statistics) Line (geometry) Cartesian coordinate system System call Word Query language Statement (computer science) Fuzzy logic Finite-state machine Object (grammar)
this is the kind of humor and and so welcome to a relentless pursuit of rest mining the
biomedical literature at up recover Boston office and I'm super excited to be here taking off rules come with you all and I do feel like I won the lottery because I get to go 1st and then I get to enjoy the rest the competency all agree talk you get 11 worry about this presentation at you but my 2 hands right at the end screensaver feedback during this talker after talking Tweedy their mean in the hallway and we're only constant puppets like to hand out so you can find me later in doesn't cool notebooks and potentially some teacher and things like that so essentially this is the talk
about restaurants so what is it not encounters kidding about that I'm not gonna recap Roy Fielding's dissertation here there's been plenty of conference talks on this in fact it was alluded to in the opening here this is the 12th real and at every single rails count there have been at least 1 presentation about rest so why should this rails company different of you know it is news conference that we also have probably hundreds of blog post developed by the community probably about half a dozen books or so and hours a podcast material some of which I am responsible for them and recover of a refrain among a lot of that content is that somehow we're
doing restaurant this can be any number of ways that we're doing restaurant as programmers but a lot of us tender love semantic arguments and rest seems to have plenty of them for us to have so we do see rest is all about the power of HTTP on
some level so there's plenty of argument for us to have their you have an API doovers that API with a slogging new URL perhaps should you instead be using the Accept header and content negotiation if you're going be more restful many so a few years ago now there was a pull request rails to change support for to add support for the password because that was more semantically correct and how we're using put and I remember the time I had really strong feelings about that 1 and I was like that we really should be using patch and so now we can and nothing is changed the and then there was this hypermedia it was kind of a high alternately red is like an extension of rest rebrand of rest it was all about providing additional U L's spirit clients to use to get more details about the about your resource at the the big idea being that clients shouldn't be building their own URL uh you should you should provide them for it for them mn of whatever this is
I think it has something do with hypermedia but to me it just always sound like mean cheerios I thank you the of so the secret is that you none of that stuff
really mattered as much as I thought it was but literally really strong feelings I had about patch like I alluded to nothing changed when that became a reality None of those things make me happier or more productive developer or make my application more successful most of us in this room I'm guessing work on a single out or maybe an API with a small number of clients that we control because we also write those clients we work with the people do or we have a business agreement with the company that does or something like that and in those cases in all cases really it's consistency that matters we can make those decisions that I alluded to before and make them consistently and we can move on the rest of the decision there rather academic and that's not to say that you shouldn't care about them at all you should have opinion and you should discuss them but I believe that the importance we put on them is outside to the benefit so this is the talk
about Rosso automated talk but I but how rest makes my code better in my job easier how it makes my code user read easier to maintain easier to expand and how can ease Rails app growing things that we all experience To that end the max you spend a lot of the talk talking about
nouns and verbs interest violence that
resources and actions so resources being your domain objects and actions being the things you can do with them this is the very very basics of rest certainly it lacks the marketing appeal or something like hypermedia for a user focus on resources and actions the dry storage creating
more small things because it's small things small controllers small models small view small objects those are the antidote to all the riddles and I patterns I encounter on application after application the so yes in
this talk we talk about some common and I patterns that I do encounter a regular basis and guessing that you do as well were talk about how RESTful design helps us to avoid incorrect those aren't like that the 1st part a common custom actions
there's nothing special about the 7 default actions the rail scaffold controller give you right you get new an update create all other wants you feelings certainly didn't bless any set of actions maybe would've been best if he did but he didn't but this is the case for strictly following that convention over configuration the David talked about the help us to avoid many of the pitfalls it's the 1st step along some level of on avoiding a lot of event factor the before you start with that is
quick 2nd to talk about how I get started on Rails application so if I'm coming onto rails brought establish Rails application the very 1st thing I do is open up rats star because a good routs file can tell me a lot about your application right you can tell me all the capabilities of your application do so very succinctly and it can tell me about the language other not not Ruby but like the business language of your application where we actually working with a bad roads while also tells me a lot of application tells me where affine large controllers or which code and in the divine may need to read the word understand what is your application doubts so thought we could start with a slice of a rat file that
obviously simplified slice of around file that I commonly see in Rails application so here we can see on the 1st line we have a singular user resource so right away just experience that tells me they single-user is likely the current user and we support and an update action which is then adding the user record or updating user records some air perhaps the user profile something like that and then there's these 2 custom member there sort hanging out here they seem relatively harmless but I really wanna know how to edit password and update have hardly differ from editing and updating user and why they on the user's controller so I really wanna dive into that uses control and see how things what why those choices were made but before we do that I wanna take just a quick parts and look at what those rats those Member rats in the middle there would look like if we wrote them out longhand without the use of the resources itself they look something like this tha what the the and they were focused on the controller mappings there if we break those out we have users edit password users update password there's a pattern there that pattern is now verb noun that patterns a dead giveaway they were missing a resource I see this a lot of applications and the resource of a missing is actually right there in the action and right the resources passwords passwords edit passwords update and that pattern is a more familiar noun-verb at were manipulating a password In these actions were not manipulating the user the fact that user is that the packet passwords ultimately stored on the user's table is inconsequential to the resource that we're dealing with so we can fix this in our rats in our file by creating a password resource another singular resource we don't need to create a password model for this to work the and here we put password proper place of prominence here it is the thing that we're working on is the thing where editing it is the thing we're updating and we get to use our conventional edit and update actions here's where passwords controller looks like all the done is copy over what used to be and password update pattern into a new group new controller called and update rules and use around updated some helper so that our past pass arrays in our 1st at this point that has to be some questions
the possible objections they come up a
common 1 is that this can't be worth another controller right no it will I would wonder what is a pedophile costs us that is very very lightweight right the and I and ultimately my response to this is that never once In the many years I've been doing development regretted extracting a controller I've never wish my controllers were bigger I always wish I had more of them that were small so any chance you can take to create another controller you're wise to do so the it's also often a 1st step towards larger refactoring that will see throughout this talk the the 2nd objection is more of a realisation usually not not so much as objections that password isn't a model here as I as I talked about were so used to there being a one-to-one correlation between after record models and our controllers they can feel wrong somehow to stray between the stray from that and as I read the real scaffold generator earlier and and that's certainly encourages this one-to-one correlation Darius scaffold you get a model you get control you get getting views like that and the books and tutorials written about rails often reinforces when you want to introduce new functionality or change functionality just either generate a new scaffolder generate a new controller in a model something like but the key takeaway here is that our controllers do not need to
map to Active Record objects one-to-one are controllers can map to a single column on Active Record object or to just a plain old Ruby object that is persisted anywhere that helps us for whatever reason In this realization was a light bulb moment for me and speaking to countless other developers they profess that also was for them as well it's more it's often highlighted is like the 1 realization that really improve people's rails the because where does it freezes up to build small objects to bridge between our controllers and our models and what us not expose the specifics are our model implementation at our controller layer controllable level we can see an example of that in our next editor
so complex actions and talking about here is like really long controller actions perhaps going out to several private method something like that they tend to be very difficult to read very difficult to test and resistant to refactoring that hard to break off pieces of them without messing up some other part but the key thing to realize here is that oftentimes we can rethink complex actions into several smaller actions across several resources and this is often appropriate to do the 1st thing I wanna call out is that
nobody comes into work thinking like I really can't wait to write some controller code today I this is kind of thing that happens we write complex controllers over time In the beginning our controller actions are just the way we like in the super boring for example we may have a controller Action allows users to update the caption on a photo that they've uploaded and action might look something
like this you don't need to read every line here right you can just kind of get a sense for was doing for the shape of it because you've written the controller like this before problem it's boring it's wonderful how boring this coders I a citizen every 1 of our controllers unfortunately it seems as if no boring controller like this survives 1st contact with the users are a product of for not diligent about it before long a news story might come along this seems pretty harmless as a user I want to mark a photo as featured so it's displayed prominently on my profile so my immediate thought years OK men ad featured column on photo is just another call the gets updated just like we have a caption I really change much at all no problem so we do that and we submit that the Proctor the tests that come back as I I forgot ciliation told you what you're only allowed to have 1 feature for OK so I guess we have a conditional for when you go from something that wasn't featured to something that is featured and we define the previously featured photo and update that so it's no longer features aaai cool we can do that so we submit that and there's 1 more thing comes back and says ah I was able to on feature my final photo and I really want that to happen we should just take the 1st part of the feature II that seems arbitrary but these things happen in here it is this is a real feature that I have developed at so you know any any might think long and hard and best case near you come up with a controller action you update your update controller Action to look something like this which is kind intentionally hard to read here on it's interesting we right and if we zoom in on the new method that update photo private method we've we've extracted there's a lot going on here but we don't have to record transactions we've got a compound conditional we have an ELSE IF which just the spelling alone in Ruby makes me kind of go from I probably shouldn't be using that the but that and it's not bad that whole thing is not bad by comparison to what you're probably thinking of when I say complex actions but as a spoiler if you're paying particular attention to the code and the requirements is also not correct and How could it be right business logic like this and controllers In conditionals and controllers like this are often not tested and as such have bondsman so how did something so that had featured it seems so simple end up putting us here which again not probably not as bad as your complex actions but if it's on slide the problem is 1 of different perspectives we wrote our original controller thinking that we are updating at tributes on a model where each activity was of equal importance the new feature requires us to treat a certain attributes differently right we have to kick off a process 1 actually is now more important than the others and the behavior differs based on which way that actually changes whether it's going from false to true true false the dissonance in those perspectives what results in the complexity we saw and we can resolve that complexity result that dissonance by getting back to being boring with rest
will introduce a featured flag resource to represent flagging an unflagging photos are photos controller goes back to what we previously had its super boring for that we saw earlier and nature our new controller is equally boring and here's how that might end up looking is deceptively it's got a deceptively small font here because now it's 2 actions but if we zoom in on create we can see it is almost identical to the boring photos controller we showed before the Finder change because the parameter change and now we're using a service object if you see here the ad feature flag that service object to get the work done but we maintain that familiar boring shape our controller the same things to our destroy action using a different Service object or object Jonathan like service and our so here's a 1 of those Service objects are objects might look like so here's our ad feature service object you can see this is also pretty boring shape it's not perfectly factors I would read as I might write it but it's also not very interesting all of the complexity and the original controller the controller we showed the habit complexity that all that is now gone right the compound conditional the if else it's all faded away into the rats right those decisions were all made before our controller code even ran so as a result this is also going to be significantly easier to test I can you test this or model test or whatever you wanna call this kind of task depend on the database for right I can test this in isolation somehow and I can overriding feature test they have a pretty good conference this is correct the
lesson here is that we need to be boring your controller should be boring your model should be boring why for started rails is common to hear that models the controller and we'll say that as much anymore because we really want small things everywhere we should be saying is boring model boring controller boring object there's something really satisfying taking code that was complex or perhaps clever and breaking into something into into component pieces that are boring so as we add complexity to the application we wanna make sure that the code we're adding is as boring as possible tha
you know when I'm reviewing about smile or control or action by often encountered the 30 that pattern unambiguous language for 1 minus how many of us
out there have been orders controller with a process action or something similar right was process do was it means a process in order that would likely depend on who I am by somebody who works in the warehouse was
processing mean that it's only it's how they may be needed in tell that's how they don't pick an order and they prepared for shipment if I ask somebody manages inventory maybe they'll tell me it's act nodes actually dispatching of orders to the proper warehouse to be fulfilled from or fastening
finance item that there it only crossing the charge greater charge collecting the money this might seem
trivial after all we're talking about the code so as long as those involved in the development of the project agree what process means there's any of this matter ultimately having ubiquitous language throughout your application and in the business it would go and share Is it mutation that everybody among everybody who cares about that system right we wanna do is avoid translating between the business terms and the terms used in the code because that results in confusion the results and people making the wrong change because the product owner has for in the language of the sales people and you implemented in the language of those so
process doesn't tell us anything to figure out which means we have to go source so OK let's open up this this orders control which ensure very boring the but so again need to fit stuff on the slide here so the real action in the real controller would be a lot harder sigh for them but these controllers tend to begin with an indissociable entanglement of conditional before actions at the top and those before acting the possibly order dependent and worst-case scenario which I've seen several times they mutate some sort of instance and for instance state along the way so we pick our way through all that and then we drop down into a process action itself and that calls out into several private methods which we have to kind of unwind and those depend on instance state as well and so we we go through all this process and we discovered that we were actually talking about a shipping order processing order is equivalent to shipping so why don't we just say so so let's just say so but we can say so because this is awful it this somehow reads worse than process of the where right where we putting the ship I don't know and the problem is we don't we don't need a better word what we need is a resource so let's do that instead were not putting a ship were creating a shipment this language works even if you're not ultimately inserting a database wrote somewhere you can use create it's fine the but we don't need to change the underlying implementation the so here's where shipments controller looks like now we pull over all the before actions we need they're no longer conditional that's kind and you know we we take the process actually make that our create and we pull over any private method that it needed right this bipolar I literally mean copy and paste that by the mountains not every and we said that this is a poll request the say we've improved alignment of the application isn't this great at this point we tend to get a
little bit more heartfelt in the objection work of yeah I just told you a copy and paste
and budget code so I did duplicate lot we do we get a lot of private methods to make it work and some of their pride another the duplication is just duplicated typing like the finders and things like that and not worry about that but some of it may actually be duplicate knowledge that would be nice to have somewhere is breaking out that new controller is what it takes the highlight this but it's worth it every single time I wouldn't rush to go ahead and make those extractions now like let them sit for a little bit and make sure they make sense this this change stands on its own their friends and that's like the say the duplication is cheaper than a rod abstractions from the liver this duplication for a little bit and see where it takes me but this change does stand on own and the larger objections I didn't actually improve the
code here ubiquitous language improvement is worth the P N emerge no 1 else is going to have to wonder what process means were already talking about the same thing consistently as long as we we know the developers of of same process but but there's something else a value that this is done for the undergoes breathing room right is the best way the best lag explains to drop comparison to writing something writing a blog post or a paper a conference talk something like that and you may in your writing you may have a sentence went into a paragraph somewhere that isn't sitting right with you it feels important and you want to say it but it's it's just not working so you try reworded a few different ways but still not great and then pulled out into its own paragraph and suddenly you realize the problem was that you had a lot more to say and you can start to expand expand on that and it starts to make more sense itself and serves to strengthen the things around as well that process is
akin to goings going from something like this in our code right we get this tangled Masson were try to figure out where the steel string goes and so were pulling out and we realize all this is a totally separate peace until string over here right in which I make improvement on something like this to something more like
this or holding a single piece of bread and were still not quite sure what to make of it but we can pull out and we can see where it goes so we wanna get to this state because that's where we can really start to impact the rest of the application right so where do these things often go state I calling
state-machines themselves nearby pattern is harsh right state machines happen someone actually a lot of our work orders kind of transition among various states of fulfillment pretty naturally by prominent so much with the idea of a state machine it's more how the commonly
implemented in Rails applications they typically are made up of hundreds of lines of DSL tacked onto a model and that now an idea cell expresses all the possible events and transitions and validations and potentially methods the overridden in various states and all gates tucked into our order model for instance because that happens to be home to the state column and so we show that all in their assign I might be in store for something like this
would be seen as the rats well when I see this is a good indication that and infer large controller back by staging so I might go ahead and take a look at that word model and find figure out what's the state machine going so here's the beginning of the so I came here to figure out what happens when water authorized so like OK here are our events right here at the top right no no other transitions or don't know cannot transitions the Caulobacter transitions OK right book all I care but all I care about is authorized so OK I see on the 3rd line that's authorized over that's going authorized to capture but the 5th line is going from pending authorized that's like here right and it authorizes the payment but does it after transitions and what that means into this class no had authorize a payment right that a big so and so here the various events we support the scroll down and speaking and some not so bad is less than a handful of them great and OK here's the transition we authorized we go from tending to authorized the nice thing about this is like they're very it's a very linear progression among the states so not too bad and here's some custom class behavior based on the state we have different validations based on whatever state the thing happens to be and we may actually as I alluded to earlier have methods the overwritten or methods only exist on a certain state is that the whole thing looks like this certainly isn't a pathological case but it's also not boring it's extremely dense when I'm reading through this code and usually trying to answer a specific question about 1 particular event and left much like an our orders controller example the trying to piece together the entire thing by going through a thing of callbacks and then the transitions in the states and the other stuff it is this all tested probably not the somebody went I'm sure they tested misleading the distinction state
machines or magnetic rate they attract more states and more transitions and more events and more callbacks and they accumulate conditional logic which is where about states and transitions that fall out of use are almost never cleaned up because no one's clear that there no longer in use anymore many of the recent project I worked on at 200 304 aligned state-machine definitions this is not uncommon I don't work on extremely pathological project all the time so how is rest thinking going to save us down here all the way our model still was 1 for my friend on preventive
pretend for just a moment the update didn't exist what associated records would you need to create In order to properly reflect the state of your order those are the resources you need to care about so if we did that in our example we may end up with us
right we've created resources for authorization capture refund a rejection and support creating those resources thinking resourcefully here gives us that breathing room I alluded to earlier to reconsider the interaction between our controllers our models each of these state transitions can now be encapsulated by an object if we want and the objects may still well update that's the column on order that's perfectly fine it or we may actually in certain associated records instead also works fine tha if we so in addressing each of these aren't I patterns spoke sorry but thought about this 1 I so what used to be
encoded NASA transitions in events is now just like this boring object here so this is this is what would look like if we extracted authorization thing into an object or service object or process object a command object where we would call these things but it used to be a bunch of DSL is now just a boring Ruby class and it's boringly shapes and I wanna know what happens when an order is authorized I open up this file and it tells you and if we want to change what happens when an order is authorized this is so lightweight but there's no sunk-cost al-Sadr overcome we can throw this away and start again without worrying about losing some sort of context that we didn't understand about authorizing the water so anything that drives us towards these types of small plane Ruby object is going to be a win for RL fabrication so in addressing each of these aren't I patterns we thought about our application from the outside in we reading outside in a a lot of us have been preaching outside in development for quite some time generally when talking about test-driven development but outside and development works equally well when designing a domain object interaction and it results in similarly similarly better design and better code what what we're doing is changing the language of the application from what is its application store and how does it story to what is it that this application does at the highest level there's still an overriding objections that
I often hear too much of the advice in this talk and some of you in this room may be thinking it and that's note this is fine for
products but my up to different the my snowflake it's much more complicated than what you're letting on this is fine for base camp my projects a lot more complicated orbital perhaps maybe I just wanna use RPC or whatever some you like don't really like rats that much so what I found after act is that in most cases what's keeping any out from being just a crowd out is a lack of imagination haven't gone back to rethink the problem from the outside in to identify the resources that you're actually talking about and he
wants to be a crowd at believe me the to believe but because apps are boring right and I hope you know I hope you know by now boring I mean that the most sincerely complementary way you wanna be a product that because rails is really really good at products and you've chosen to write or have been stuck with maintaining a Rails application so when doing that being boring the RESTful don't worry about response codes right identify the real resources in use in your application and design your entire system from that perspective from the outside and don't worry about the vagaries of your data model the data store any questions I and so the question was
how you handle statement in state-machine exam a sorry a out of the example the wizard right a multi-step process that may be a B and creates or updates 1 record and can depend on the specifics of what you're trying to get done but I did recently due the same type of thing where people were going to this registration wizard and telling us a bunch of information about and the facility their onboarding and the way we did that was have them in step 1 they create the shell of the resource in step 2 we model that as as uh like associated records even ultimately it wasn't so they were all associate record some things were like an address would then be associated to the thing in the next step on and there may be a state thing at the end that happens to say guess they've checked all the boxes and the wizard is now complete but trying as much as possible thing about breaking out up into different resourceful steps it is kind of dependent on them on on exactly where dealing with the so the question was a com objection is that it's fine it's it's basically find do this here but you have a you have addressed it everywhere else that like now now we have a different pattern used in lots of ways the so that it is a common objection you're right about that but the I have I mean we have to be trying to make the application better and if people can agree that yes this is better we should be moving to this but I think you do it right so and no you update your things as you as you have need to and the other is there does tend to be some push back about the of you now is a different pattern we of so we've never had a service object anywhere now we have a service but that's an improvement in the team can agree that that's an improvement the ot the options is stagnating anything that you agree is not the optimal solution so and that's where I would put it so where I would put so the question is where did all the complexity that was in a state machine go when I showed the example of the extraction but done and I would expect you controller what I what I actually cited there to remind the word dog explaining it was that was the service object the controllers going to use and I would put all as much as I could of that there right but then there was if we go back I don't know how far back it's but not too far OK so there was this like idea of whether or not something authorize a ball on the bottom and that would be like the conditional validation perhaps and the before transition after transition stuff now just kind goes away in the middle of this process work already won a call that the main method of this object here I'm because it does the transition of updating the order and then it calls the authorize thing that was at that what we were doing in our state machine at that point and so moving out as much as possible into a service object heard of collection of objects that work together the and testing those individually and I think this read this really does kind of encapsulate a lot was happening as the machine but and I think is read significantly easier I haven't thought about it from that perspective I think the generators or super useful but I still use them on occasion like when I need to remember what a villa a controller looks like a and if I don't know the the solvable problem you generate code I don't know that like the generator could know exactly what the best thing to do was on for the video the question was should should we update the to we update the from generators to be more in line with approach like this so the question is about the alternative action names like reorder if you have a collection of your collection something you wanna reorder them so we really your action but in how they handle that and yes I would typically like and going back to our photos example if you reordering all the photos I might create an album instance right and you can update that album instance with an ordering of its component photos or something like that or positions controller like you alluded to in your question something like that and but there's no reason the collection of objects can be a resource in and of itself but so the title so the question is on making and and making a rails engines zoning but OK so making API for an engine and the action is start the engine how would I make a nice resource for that the the going I thought my head I don't know the engines start request create the hands of the engine update share the I mean that's up to you and your team but I think i'd I don't know about not trying to say that you should never have a cost action but I'm saying it should be default never have a custom action you should agree with your team that like here a custom action make sense to me I just have to think that answer is almost never but you may differ slightly i disobedient differ to the point of creating custom actions in your control all the time but the laughing of my favorite questions the question is where you place these things right and I always ask that question because so nice when you above happen you have like models of this new that wherever she could and item but mean AP services apps objects app boring I know but but just pick thing I I worked at a party before we actually broken down based on the types of things they were they were like a command object or if they were a query object that's a common thing like AP queries all see for like query for complex periodic objects just degree the team what you want to and use of fuzzy Finder-like control the and then define the file anyway you have cool any also tha are they surveyed fair there are so how he
finds lands