Загрузка...

RubyC-2018 / Tim Rogers "Miles more maintainable: building APIs with the middleware pattern"

When you’re building an API, things start off simple. But before you know it, there’s lots of logic you want to build abstractions around and reuse - for example authentication, input validation and pagination. This usually means having a long list of callbacks living in your `ApplicationController` using ActionController’s `before_action` magic. This leads to: tangled data dependencies (where callbacks depend on data retrieved by other callbacks and stored in instance variables - the authenticated user, for example) hidden behaviour (all those `except`s and `only`s on your `before_action`s are hard to reason about and separated from your code, usually living in `ApplicationController`!) difficulties with testing (unit testing methods inside a controller is hard!) The middleware pattern can help us to bring sanity to our APIs and make them miles more maintainable. This pattern, used by Elixir’s Phoenix, Node’s Express and even Ruby’s Rack helps us to untangle our data dependencies, make our code much more explicit and easily unit test complex behaviour. We can apply this pattern to our Rails application to move faster and write more maintainable code. In this talk, you’ll learn how to move from convoluted controllers to robust, maintainable and well-tested chains of middleware built using a open-source gem, Coach (https://github.com/gocardless/coach). *** RubyC is a European conference devoted to Ruby, Rails and other related technologies. Organizer - Svitla Systems Inc. https://svitla.com

Видео RubyC-2018 / Tim Rogers "Miles more maintainable: building APIs with the middleware pattern" автора Irresistible Indulgences
Страницу в закладки Мои закладки
Все заметки Новая заметка Страницу в заметки