Link Search Menu Expand Document

Routes actions

Inside modules’ it’s possible to add configurations that aim to execute code in relation to API calls. It’s like hooks of code that are executed before and after each API execution. They are useful to perform input checks or actions after API calls, like sending an e-mail or a push notification after a creation.

module<Game>("games") {

   beforeCreate {
      headers, game ->
      println(headers)
   }

   afterCreate { headers, output ->
      println(output)
   }

   beforeGet { headers, query ->
      println(query)
   }

   afterGet { headers, query, games ->
      println(games)
   }

   beforeUpdate { headers, id, patch ->
      println(patch)
   }

   afterUpdate { headers, patch, game ->
      println(game)
   }

   beforeDelete { headers, id ->
      println(id)
   }

   afterDelete { headers, deleteResult ->
      println(deleteResult)
   }
}

For userModule 2 more actions are available, to support login and logout

userModule<User> {

   beforeLogin { headers, input ->
      println(input)
   }

   afterLogin { headers, input ->
      println(input)
   }

   beforeLogout { headers ->
      println(headers)
   }

   afterLogout { headers ->
      println(headers)
   }
}

Copyright © 2021 Dario Pellegrini