{"action":"created","issue":{"url":"https://api.github.com/repos/basti1302/traverson/issues/39","labels_url":"https://api.github.com/repos/basti1302/traverson/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/basti1302/traverson/issues/39/comments","events_url":"https://api.github.com/repos/basti1302/traverson/issues/39/events","html_url":"https://github.com/basti1302/traverson/issues/39","id":64496830,"number":39,"title":"How to add an additional query parameter?","user":{"login":"bluish5","id":11028113,"avatar_url":"https://avatars.githubusercontent.com/u/11028113?v=3","gravatar_id":"","url":"https://api.github.com/users/bluish5","html_url":"https://github.com/bluish5","followers_url":"https://api.github.com/users/bluish5/followers","following_url":"https://api.github.com/users/bluish5/following{/other_user}","gists_url":"https://api.github.com/users/bluish5/gists{/gist_id}","starred_url":"https://api.github.com/users/bluish5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluish5/subscriptions","organizations_url":"https://api.github.com/users/bluish5/orgs","repos_url":"https://api.github.com/users/bluish5/repos","events_url":"https://api.github.com/users/bluish5/events{/privacy}","received_events_url":"https://api.github.com/users/bluish5/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-26T11:02:32Z","updated_at":"2015-03-28T09:43:41Z","closed_at":"2015-03-28T09:43:41Z","body":"Hello, thanks for this good component!\r\nI'm using it like this:\r\n\r\n\ttraverson\r\n\t\t.from('rest/bookings/search')\r\n\t\t.newRequest()\r\n\t\t.follow('findByResource', 'bookings[$all]')\r\n\t\t.withTemplateParameters({\r\n\t\t\tresource : 6\r\n\t\t})\r\n\t\t.getResource(function(error, document) {\r\n\t\t\tif (error) {\r\n\t\t\t\tconsole.error('Bookings not found');\r\n\t\t\t} else {\r\n\t\t\t\tcallback(document);\r\n\t\t\t}\r\n\t\t});\r\n\r\nIt works.\r\nIn my RESTful web service, built with Spring Data REST, I'm using \"projections\". In short, I can request a particular set of information on the resource I'm asking, specifying `projection=nameoftheprojection` as an additional query parameter.\r\nAt the end my URL will be:\r\n\r\n    http://.../rest/bookings/search/findByResource?resource=6&projection=details\r\n\r\nAnd then I have to follow `bookings` node, like I did in the code above.\r\nHow can I add such parameter using Traverson!\r\nKind regards"},"comment":{"url":"https://api.github.com/repos/basti1302/traverson/issues/comments/87198158","html_url":"https://github.com/basti1302/traverson/issues/39#issuecomment-87198158","issue_url":"https://api.github.com/repos/basti1302/traverson/issues/39","id":87198158,"user":{"login":"basti1302","id":73801,"avatar_url":"https://avatars.githubusercontent.com/u/73801?v=3","gravatar_id":"","url":"https://api.github.com/users/basti1302","html_url":"https://github.com/basti1302","followers_url":"https://api.github.com/users/basti1302/followers","following_url":"https://api.github.com/users/basti1302/following{/other_user}","gists_url":"https://api.github.com/users/basti1302/gists{/gist_id}","starred_url":"https://api.github.com/users/basti1302/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/basti1302/subscriptions","organizations_url":"https://api.github.com/users/basti1302/orgs","repos_url":"https://api.github.com/users/basti1302/repos","events_url":"https://api.github.com/users/basti1302/events{/privacy}","received_events_url":"https://api.github.com/users/basti1302/received_events","type":"User","site_admin":false},"created_at":"2015-03-28T09:43:41Z","updated_at":"2015-03-28T09:43:41Z","body":"`withRequestOptions` should do the trick.\r\n\r\nLike this:\r\n```\r\ntraverson\r\n    .from('rest/bookings/search')\r\n    .newRequest()\r\n    .follow('findByResource', 'bookings[$all]')\r\n    .withTemplateParameters({\r\n        resource : 6\r\n    })\r\n    .withRequestOptions({\r\n        qs: { projection: 'details' }\r\n    })\r\n    .getResource(function(error, document) {\r\n        if (error) {\r\n            console.error('Bookings not found');\r\n        } else {\r\n            callback(document);\r\n        }\r\n    });\r\n```\r\n\r\nDocs:\r\n\r\n* https://github.com/basti1302/traverson/#headers-query-strings-http-basic-auth-oauth-and-whatnot\r\n* https://github.com/basti1302/traverson/blob/master/api.markdown (see `withRequestOptions` section)\r\n* https://github.com/request/request#requestoptions-callback\r\n\r\nThis should work well but actually an even  cleaner solution might be if your server side would include `projection` as an optional parameter in the URI template:\r\n\r\nhttp://.../rest/bookings/search/findByResource?resource={resource}{&projection}\r\n\r\nSee https://tools.ietf.org/html/rfc6570#section-3.2.9\r\n\r\nBenefit: Your API communicates to clients that this parameter can be used and it is no longer implicit knowledge, also you can omit `withRequestOptions` and just use `withTemplateParameters` with two values instead of one."}}