{"action":"created","issue":{"url":"https://api.github.com/repos/baugarten/node-restful/issues/129","repository_url":"https://api.github.com/repos/baugarten/node-restful","labels_url":"https://api.github.com/repos/baugarten/node-restful/issues/129/labels{/name}","comments_url":"https://api.github.com/repos/baugarten/node-restful/issues/129/comments","events_url":"https://api.github.com/repos/baugarten/node-restful/issues/129/events","html_url":"https://github.com/baugarten/node-restful/issues/129","id":154845075,"number":129,"title":"Before","user":{"login":"estevo-de","id":2319882,"avatar_url":"https://avatars.githubusercontent.com/u/2319882?v=3","gravatar_id":"","url":"https://api.github.com/users/estevo-de","html_url":"https://github.com/estevo-de","followers_url":"https://api.github.com/users/estevo-de/followers","following_url":"https://api.github.com/users/estevo-de/following{/other_user}","gists_url":"https://api.github.com/users/estevo-de/gists{/gist_id}","starred_url":"https://api.github.com/users/estevo-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/estevo-de/subscriptions","organizations_url":"https://api.github.com/users/estevo-de/orgs","repos_url":"https://api.github.com/users/estevo-de/repos","events_url":"https://api.github.com/users/estevo-de/events{/privacy}","received_events_url":"https://api.github.com/users/estevo-de/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-14T09:58:55Z","updated_at":"2016-05-14T13:57:27Z","closed_at":null,"body":"Hi I found the .before Method interesting. I tried to use it without success perhaps cos I am using it together with register. It would be great if there are examples how one would be able to use it.\r\n\r\nI have checked the lib and based on comparing .before with register somewhat I think I am missing out on a parameter for .before.\r\n\r\nThank you.\r\nBest regards\r\nAshar"},"comment":{"url":"https://api.github.com/repos/baugarten/node-restful/issues/comments/219221735","html_url":"https://github.com/baugarten/node-restful/issues/129#issuecomment-219221735","issue_url":"https://api.github.com/repos/baugarten/node-restful/issues/129","id":219221735,"user":{"login":"baugarten","id":805610,"avatar_url":"https://avatars.githubusercontent.com/u/805610?v=3","gravatar_id":"","url":"https://api.github.com/users/baugarten","html_url":"https://github.com/baugarten","followers_url":"https://api.github.com/users/baugarten/followers","following_url":"https://api.github.com/users/baugarten/following{/other_user}","gists_url":"https://api.github.com/users/baugarten/gists{/gist_id}","starred_url":"https://api.github.com/users/baugarten/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baugarten/subscriptions","organizations_url":"https://api.github.com/users/baugarten/orgs","repos_url":"https://api.github.com/users/baugarten/repos","events_url":"https://api.github.com/users/baugarten/events{/privacy}","received_events_url":"https://api.github.com/users/baugarten/received_events","type":"User","site_admin":false},"created_at":"2016-05-14T13:57:27Z","updated_at":"2016-05-14T13:57:27Z","body":"Hey Ashar -- you can looks at the README.md for examples on how to use `before` and `after` properly. To quote directly,\r\n\r\n```js\r\nResource.before('post', hash_password)\r\n  .before('put', hash_password);\r\n\r\nfunction hash_password(req, res, next) {\r\n  req.body.password = hash(req.body.password);\r\n  next();\r\n}\r\n\r\n// ...\r\n\r\nResource.after('get', function(req, res, next) {\r\n  var tmp = res.locals.bundle.title; // Lets swap the title and year fields because we're funny!\r\n  res.locals.bundle.title = res.locals.bundle.year;\r\n  res.locals.bundle.year = tmp;\r\n  next(); // Don't forget to call next!\r\n});\r\n```\r\n\r\nOf course, the APIs for `before` and `after` are the same\r\n"}}