{"title":"Filters","description":"","section":"guides/controllers","version":"v1.5","path":"guides/controllers/filters","canonical_url":"https://amberframework.org/docs/v1.5/guides/controllers/filters","markdown_url":"https://amberframework.org/docs/v1.5/guides/controllers/filters.md","inherited":true,"content_markdown":"# Filters\n\nFilters are methods that are run \"before\", \"after\" or \"around\" a controller action.\n\nFilters are inherited, so if you set a filter on`ApplicationController`, it will be run on every controller in your application.\n\n## Before filter\n\n\"before\" filters may halt the request cycle. A common \"before\" filter is one which requires that a user is logged in for an action to be run. You can define the filter method this way:\n\n```crystal\n# Filters are methods that are run \"before\", \"after\" a controller action.\nbefore_action do\n  # runs for specified actions\n  only [:index, :world, :show] { increment(1) }\n  # runs for all actions\n  all { increment(1) }\nend\n```\n\n## After filter\n\n\"after\" filters are executed after the request cycle. A common \"after\" filter is one which requires to cleanup user data after an action has been run. You can define the filter method this way:\n\n```crystal\nafter_action do\n  # runs for specified actions\n  only [:index, :world] { increment(1) }\nend\n```"}