How to restrict route to a role in Drupal 8

To restrict a route defined using routing.yml to the user having a certain role use the following snippet.

your_module.your_restricted_route:
  path: '/any-route'
  defaults:
    _form: '\Drupal\your_module\Form\RestrictedForm'
    _title: 'Restricted Settings'
  requirements:
    _role: 'role1+role2'

This route will only be accessible for user have 'role1' or 'role2'.